Using ogr2ogr I was able to import a shapefile into SQL server, but it was imported as a geometry data type and not compatible to compare it to latitude longitude as the points were not correct on the polygons.

gdal\bin\gdal\apps\ogr2ogr -overwrite -f MSSQLSpatial -lco SRID=4326 -lco GEOM_TYPE=geography -a_srs "GIS\Kentucky\HH001M01.prj" "MSSQL:server=.\;database=GISData;trusted_connection=yes" "GIS\Kentucky\HH001M01.shp"

The last command I ran was above, but it gave an error that the Latitude values must be between -90 and 90 degrees. Which makes sense, but I don't know how to apply the project correctly to get it to convert the shapefile to the right format.

Am I missing a parameter to ogr2ogr or have I specified something wrong?

Data HH001M01 is the data I am using here.


If you want transform the shapefile to the server in lat/lon, use -t_srs EPSG:4326.

The options -a_srs <some non-lat/lon projection> and -lco SRID=4326 logically conflict. I don't think you need -a_srs for this operation, since it would implied to be the same as -t_srs.

  • This got me going in the right direction. I had to remove -lco GEOM_Type=geography and then run the sql below. Something about the left hand rule and when it was a geography type it took over the entire globe, but geometry it worked. I still had one record that was correct, so I had to flip it by updating one record without ReorientObject() UPDATE [hh001m01] SET [ogr_geometry] = [ogr_geometry].MakeValid(); ALTER TABLE [hh001m01] ADD ogr_geography geography; update [hh001m01] SET ogr_geography = geography::STGeomFromWKB(ogr_geometry.STAsBinary(), 4326).MakeValid().ReorientObject() – Josh Jun 8 '17 at 2:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.