[gdal-dev] Shapefile to SQL Server

Mike Colbert mcolbert at unicon-intl.com
Fri Apr 15 08:06:17 PDT 2016


Hi,

I have a Java web app with a SQL Server database and I would like to add support for importing shapefiles.  The shapes will then be used to determine if geographic locations we have defined in our system are within the areas defined by the shapes.

I've gone down the path of using ogr2ogr from Java to connect to SQL Server and load the shapefile.  However, I'm getting an error on a particular file I will need to load.  I'm wondering if I'm missing an option on the command?  Using a different shapefile, it seems to work.

Here is the command and the error:

String[] cmd = {
                                "-overwrite",
                                "-f", "MSSQLSpatial",
                                "MSSQL:Server=xxx;Database=xxx;Uid=xxx;Pwd=xxx",
                                "C:\\Users\\mcolbert\\Downloads\\UGRB_Ozone_NAA\\UGRB_Ozone_NAA.shp", // error on this one
//                            "C:\\Users\\mcolbert\\Downloads\\tl_2010_06_zcta510\\tl_2010_06_zcta510.shp", // this one seems fine
                                "-lco", "GEOM_TYPE=geography",
                                "-lco", "GEOM_NAME=geog",
                                "-nln", "CM_SHAPE",
                                "--debug", "ON"
//                            ,"-a_srs", "ESPG:4269"
                                };
ogr2ogr.main(cmd);

OGR: OGROpen(C:\Users\mcolbert\Downloads\UGRB_Ozone_NAA\UGRB_Ozone_NAA.shp/00000000003FFE40) succeeded as ESRI Shapefile.
OGR_MSSQLSpatial: EstablishSession(Connection:"Server=xxx;Database=xxx;Uid=xxx;Pwd=xxx")
ODBC: SQLDriverConnect(DRIVER=SQL Server;Server=xxx;Database=xxx;Uid=xxx;Pwd=xxx)
OGR: OGROpen(MSSQL:Server=xxx;Database=xxx;Uid=xxx;Pwd=xxx/000000000042C440) succeeded as MSSQLSpatial.
MSSQLSpatial: DeleteLayer(cm_shape)
OGR_MSSQLSpatial: Using column ogr_fid as FID for table cm_shape.
ERROR 1: INSERT command for new feature failed. [Microsoft][ODBC SQL Server Driver][SQL Server]A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":

System.FormatException: 24201: Latitude values must be between -90 and 90 degrees.

System.FormatException:

   at Microsoft.SqlServer.Types.GeographyValidator.ValidatePoint(Double x, Double y, Nullable`1 z, Nullable`1 m)

   at Microsoft.SqlServer.Types.Validator.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)

   at Microsoft.SqlServer.Types.Forw
Terminating translation prematurely after failed
translation of layer UGRB_Ozone_NAA (use -skipfailures to skip errors)



I'm assuming there is nothing unusual about the shapefile.  The file is available here:
http://deq.wyoming.gov/media/attachments/Air%20Quality/Winter%20Ozone/Nonattainment%20Information/2012_AQD_UGRB-Ozone-Nonattainment-Area-GIS-Shape-File.zip

Any help is appreciated.

Thanks,
Mike





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20160415/d3897e38/attachment-0001.html>


More information about the gdal-dev mailing list