[gdal-dev] Difference between ogr2ogr and Python reprojection
Thomas Gratier
osgeo.mailinglist at gmail.com
Fri Mar 17 14:53:42 PDT 2023
Hello,
What about using gdal.VectorTranslate instead? Normally, shorter code and
it works like ogr2ogr
PS: could be wrong as I didn't tested the exact syntax
from osgeo import gdal
gdal.VectorTranslate(
'result_command_line.json',
'geojson.json',
options='-f GeoJSON -s_srs "+proj=stere +lat_0=90 +lat_ts=60 +lon_0=264
+x_0=0 +y_0=0 +R=6371229 +units=m +no_defs" -t_srs EPSG:4326'
)
Regards
Thomas Gratier
Le mar. 14 mars 2023 à 19:27, Scott <public at postholer.com> a écrit :
> While I don't have a direct answer to your question I might ask, why use
> 20 lines of python code when 1 line of ogr2ogr gives the correct result?
>
>
> On 3/14/23 11:15, Dion-Degodez,Nicolas (ECCC) wrote:
> > _Context_
> >
> > We are trying to reproject a GeoJSON polygon to EPSG:4326.
> >
> > In some cases, depending on whether we use the ogr2ogr command line or
> > the equivalent in python, the resulting polygon is different.
> >
> > In those situations, the command line gives us the appropriate polygon,
> > whereas the python code gives us a distorted polygon.
> >
> > _Question_
> >
> > Any idea why there is a difference between the command line and the
> > python results? Is there a mistake in our interpretation of the code/how
> > we converted it in python?
> >
> > _Sample GeoJSON_: https://pastebin.com/hUiVVjFv
> > <https://pastebin.com/hUiVVjFv>
> >
> > Proj4: "+proj=stere +lat_0=90 +lat_ts=60 +lon_0=264 +x_0=0 +y_0=0
> > +R=6371229 +units=m +no_defs"
> >
> > _Command line that works_: ogr2ogr -s_srs "+proj=stere +lat_0=90
> > +lat_ts=60 +lon_0=264 +x_0=0 +y_0=0 +R=6371229 +units=m +no_defs" -t_srs
> > EPSG:4326 result_command_line.json geojson.json
> >
> > Result: https://pasteboard.co/cTpZBRamEYv8.jpg
> > <https://pasteboard.co/cTpZBRamEYv8.jpg>
> >
> > _Python code_ (we would expect the same output as the command line):
> > https://pastebin.com/QgWDBL1W <https://pastebin.com/QgWDBL1W>
> >
> > Result: https://pasteboard.co/8iSv0vbnQlHw.jpg
> > <https://pasteboard.co/8iSv0vbnQlHw.jpg>
> >
> > Thank you!
> >
> > Nicolas D.
> >
> >
> > _______________________________________________
> > gdal-dev mailing list
> > gdal-dev at lists.osgeo.org
> > https://lists.osgeo.org/mailman/listinfo/gdal-dev
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230317/0eeb41b3/attachment.htm>
More information about the gdal-dev
mailing list