Skip to content

Import OSM to MSSQL on SSMS through a SQL query with an HTTP request. BOOM!!!

License

Notifications You must be signed in to change notification settings

francesco1119/OSM_to_MSSQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

issues network stargazers LICENSE

OSM_to_MSSQL

Import OSM to MSSQL on SSMS and retrieve JSON through T-SQL with an HTTP request. BOOM!!!

The Story

The idea to build a simple way to import Open Street Map to Microsoft SQL Server was born after this post when I tragically realised that there was no current way to import easily and on the fly OSM to MSSQL.

The idea became even more challenging when people start blathering that it was impossible (why?) and that OSM felt better on MySQL or PostgreSQL database.

At that stage it became personal and I started coding.

How to use

  1. Open SSMS and enable Ole Automation Procedures running this query:
sp_configure 'show advanced options', 1;  
GO  
RECONFIGURE;  
GO  
sp_configure 'Ole Automation Procedures', 1;  
GO  
RECONFIGURE;  
GO
  1. Download the query in attach and paste it into SSMS.
  2. Edit DECLARE @place as NVARCHAR(30) = 'Paris' and instead of Paris put Barcelona or Spain or whatever
  3. Edit DECLARE @amenity as NVARCHAR(30) = 'cinema' and put whatever you want from the list of the amenities
  4. Press F5 and run the query

Troubleshooting:

How it works under the hood

Every time you run the query OSM_to_MSSQL creates a table called 'OSM_' + @amenity + '_' + @place.

Re-running the query will drop the old table and recreate a new one so yes, you can stick this query into a stored procedure and your data can be fresh new every day.

How cool is that?

Let's have an argument

OSM_to_MSSQL is using sp_OACreate and MSXML2.ServerXMLHTTP.6.0 to create the request. Using sp_OACreate is considered bad practice and MSXML2.ServerXMLHTTP.6.0 is deprecated. If you are not OK with that you can use SQLCRL but don't think not even for a second that this will be safer or it will query the API better or faster or it will provide you a place in Heaven.

Future developent

On spare time my TODO list is:

  • Brake the @URL into:
    • node(area.a)[amenity=cinema]
    • way(area.a)[amenity=cinema]
    • rel(area.a)[amenity=cinema]
  • Eventually create {{bbox}} URL for retrieve data from all over the World ([bbox=-180,-90,180,90])
  • Eventually provide development for MSXML6 call

About

Import OSM to MSSQL on SSMS through a SQL query with an HTTP request. BOOM!!!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published