Wednesday 28 September 2016

georeferencing - OGR DXF to KML conversion


I'm trying to convert a DXF 2010 file to KML using ogr2ogr:


ogr2ogr -f "KML" outfile.kml infile.dxf

In the file, $INSUNITS is 6, that's meters, if I'm correct? The problem is that DXF is not georeferenced, and I get errors like:


ERROR 1: Latitude -1113854.310000 is invalid. Valid range is [-90,90]. This warning will not be issued any more
Warning 1: Longitude -684136.440000 has been modified to fit into range [-180,180]. This warning will not be issued any more

I'm pretty new to this stuff, and in the last weeks I haven't found documentation that's explaining what I'm doing wrong. Can I add a suggested lat/lon as a parameter to ogr2ogr? Is it actually possible to do a conversion DXF to KML?




Answer



I use this procedure to convert DXF coordinates (in meters) to lon-lat, when I know what the center lon-lat will be. Let's call this point (center-lon, center-lat).



  1. Use ogr2ogr to convert DXF to GeoJSON. This leaves all the big AutoCAD coordinates intact.

  2. Make a script to read the GeoJSON file, parse it with json_decode (when using PHP).

  3. Calculate the offset from (0,0) by making an average of the smallest and largest x and y coordinates.


  4. With (center-lon, center-lat) as the center, convert GeoJSON coords (x,y) to (lon,lat):


    lon = center-lon + (x - xoffset) * (360 / (e * cos(center-lat)))


    lat = center-lat + (y - yoffset) * (360 / e)





With e the circumference of the earth in meters.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...