[gdal-dev] Shapefile to SQL Server

Bo Victor Thomsen bo.victor.thomsen at gmail.com
Fri Apr 15 10:07:20 PDT 2016


The shape file in the zip is not in projection espg:4269. It's in utm 
zone 12N. Replace the "-a_srs", "ESPG:4269" with "-t_srs", "ESPG:4269" 
and "-s_srs", "ESPG: /code_for_UTM_12N/"
This causes ogr2ogr to reproject you data to the correct projection

Bo Victor Thomsen

Den 15/04/16 kl. 17:06 skrev Mike Colbert:
>
> 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
>
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

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


More information about the gdal-dev mailing list