OGR2OGR custom coordinate conversion


#1

Hi All,
I’m trying to convert coordinates using OGR2OGR function. As a bstrOptions, I use following string:

“-s_srs “”+proj=krovak +lat_0=49.5 +lon_0=24.83333333333333 +alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +towgs84=559.0,68.7,451.5,7.920,4.073,4.251,5.71"” -t_srs ““EPSG:4326"” -f CSV -lco ““GEOMETRY=AS_WKT”””

My input file (points.csv.vrt) is following:


points.csv
wkbPoint



This file is followed by standard CSV file - for instance:
X,Y
-868208.54,-1095793.58

Such setup works when using GDAL utility but unfortunately, it does not work in MapWinGIS. My output file contains only the following string:
WKT,

Do you have any suggestion of what I’m doing wrong?

Thank you very much in advance,
Jiri


#2

I see that some part of my text is missing…
My input file (points.csv.vrt):

<OGRVRTDataSource>
        <OGRVRTLayer name="points">
            <SrcDataSource>points.csv</SrcDataSource>
            <GeometryType>wkbPoint</GeometryType>
            <!--LayerSRS>EPSG:5514</LayerSRS-->
            <GeometryField encoding="PointFromColumns" x="X" y="Y"/>
        </OGRVRTLayer>
</OGRVRTDataSource>

Jiri


#3

Hi Jiri,

Can you show the MapWinGIS code you’re using?
And show the ogr2ogr command parameters so we can try to reproduce.


#4

Hi Paul,
my code snippet:

Dim sOpt As String = "-s_srs ""+proj=krovak +lat_0=49.5 +lon_0=24.83333333333333 +alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel " _
                 & "+towgs84=559.0,68.7,451.5,7.920,4.073,4.251,5.71"" -t_srs ""EPSG:4326"" -f CSV -lco ""GEOMETRY=AS_WKT"""
Dim o As New Utils
myStatusLabel.Text = o.OGR2OGR(sInFile, sOutFile, sOpt, Nothing)

Thank you,
Jiri


#5

The documentation of Utils.OGR2OGR() show this is a deprecated function and it is better to use GdalUtils.GdalVectorTranslate()
The difference between the functions is that ogr2ogr is a custom implementation within MapWinGIS of this GDAL function and the new method is just sending the commands to GDAL and let GDAL handle this.

Could you rewrite your method to use GdalVectorTranslate()?


#6

I use version 4.9.4.2 (GdalUtils class is not involved in this version). I’m not sure whether I can upgrade as I already distributed my app among number of colleges.


#7

Since Utils.OGR2OGR() is only a partial implementation I doubt you will get the coordinate conversion working with it.
That is one of the reasons we implemented GdalVectorTranslate().

A workaround might be to create an in-memory point shapefile assign the correct projection and add the coordinate as a point and reproject the shapefile to the new projection and read the coordinates back.
Useful documentation:

Let us know if this is working for you. If needed I can provide some sample code.


#8

Can I parametrize such re-projection? I need to apply my own transformation.