0

I have a work process which uses an ogr2ogr text command to convert a MapInfo TAB file to a KML file. I'm very pleased with this because it maintains the original symbology (a simple 2 colour system used for lines in MapInfo - implemented as a line style when input, not derived directly from the data).

This command also selects for certain categories of line according to some data fields in the original file.

ogr2ogr -f "KML" OutputFileName.kml InputFileName.TAB -sql "select RNumber from InputFileName where ((RType = 1 or RType = 2) and OStatus >= 3)"

Unfortunately the original file is large, and the KML file therefore is large - too large for the application I'm using it in.

I'd like to do something simple and efficient to allow me to divide the KML file up into geographical regions. If possible this should be something simple enough to describe to others too - although that's not a necessity.

I could, of course, work with a process in MapInfo to extract the lines I want first - or I could do the same with QGIS. I've tried both and hit problems - which I'm sure could be overcome - but I'd like to know if I'm missing something more obvious/simple. For instance does ogr2ogr have the capacity to do this?

As background, I've faced an issue with QGIS which is that bringing the TAB file into the application seems to lose the line colour. I could re-create this based on a data field if necessary, but that adds extra steps (I know that I could use various workspaces/projects to simplify things). I'm also not sure how to ensure that QGIS codes line colour into the KML.

I also find the processes of selecting by geographical area in MapInfo frustrating - I'll be able to solve this if necessary I think, but I end up in a tangle of SQL query issues which so far hasn't given me what I need.

  • Read gdal.org/ogr2ogr.html and maybe running ogr2ogr with -spat works for you. – user30184 Sep 22 '14 at 17:28
  • That might have potential. Could I use the -clipsrc option? Could anyone point me at how this would work (using a text tool like this has me a lot out of my depth). How do I determine the numbers for the bounding box data - i.e are these lat/lon in WGS84 etc? I'd really appreciate an example if someone could provide this. Thanks in advance - I already struggled to get to this point. – Rostranimin Sep 22 '14 at 17:34
  • -spat takes parameter minx miny maxx maxy and the values are in the same projection than the source data. X is the west-east axis and y is the south-north axis. -clipsrc behaves similarly but it splits features (lines and polygons) with the geometry used for selecting. -clipdst takes coordinates in the output projection (-t_srs) if you reproject at the same. – user30184 Sep 23 '14 at 4:50
1

This image shows the states shapefile and clipping box with extents from 130°E to -90°E and from 20°N to 50°N.

enter image description here

First ogr2ogr command is using -spat parameter for selecting features and the second one is using -clipsrc parameter which is clipping features along the selecting geometry.

ogr2ogr -f "ESRI Shapefile" -spat -130 20 -90 50 selected.shp states.shp

ogr2ogr -f "ESRI Shapefile" -clipsrc -130 20 -90 50 clipped.shp states.shp

Images show the difference between -spat and -clipsrc

enter image description here

enter image description here

  • Thank you. That's also really helpful as background. I'd concluded something like what you describe would happen. – Rostranimin Sep 23 '14 at 14:53
0

user30184 has provided the answer I needed.

ogr2ogr has the capability to work only on data within a given geographical bounding box. (I was indeed missing something obvious).

ogr2ogr -f "KML" OutputFileName.kml InputFileName.TAB -sql "select RNumber from InputFileName where ((RType = 1 or RType = 2) and OStatus >= 3)" -spat xmin ymin xmax ymax

Where xmin,ymin,xmax,ymax are values describing a bounding box.

To quote:

-spat takes parameter minx miny maxx maxy and the values are in the same projection than the source data. X is the west-east axis and y is the south-north axis.

Or if you like:

-clipsrc behaves similarly but it splits features (lines and polygons) with the geometry used for selecting. -clipdst takes coordinates in the output projection (-t_srs) if you reproject at the same.

Plenty more information here:http://www.gdal.org/ogr2ogr.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.