[gdal-dev] Filtering Null Coordinates and rounding coordinates Using ogr2ogr?

jratike80 jukka.rahkonen at maanmittauslaitos.fi
Thu Oct 17 02:37:37 PDT 2019


Works for me. Here is my test data, copy and save as "empty.jml"

<?xml version='1.0' encoding='UTF-8'?>
<JCSDataFile xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" >
<JCSGMLInputTemplate>
<CollectionElement>featureCollection</CollectionElement>
<FeatureElement>feature</FeatureElement>
<GeometryElement>geometry</GeometryElement>
<CRSElement>boundedBy</CRSElement>
<ColumnDefinitions>
</ColumnDefinitions>
</JCSGMLInputTemplate>

<featureCollection>
  <gml:boundedBy>
    <gml:Box>
      <gml:coordinates decimal="." cs="," ts=" ">380.00,320.00
380.00,320.00</gml:coordinates>
    </gml:Box>
  </gml:boundedBy>
  <feature>
    <geometry>
      <gml:Point>
        <gml:coordinates>
          380.0,320.0 
        </gml:coordinates>
      </gml:Point>
    </geometry>
  </feature>
  <feature>
    <geometry>
      <gml:Point>
      </gml:Point>
    </geometry>
  </feature>
</featureCollection>
</JCSDataFile>

The commands to run

List all geometries, including empty ones:
ogrinfo empty.jml -al

Filter out empty geometries with OGR SQL dialect:
ogrinfo -where "OGR_GEOMETRY is not null" empty.jml -al

Filter out empty geometries with SQLite SQL dialect:
ogrinfo -dialect SQLite -sql "select * from empty where geometry is not
null" empty.jml

Filter out empty geometries and scale coordinates with SQLite SQL dialect:
ogrinfo -dialect SQLite -sql "select ScaleCoordinates(geometry,0.0254) from
empty where geometry is not null" empty.jml

Changing the decimal precision does not seem be simple with SpatiaLite so
you must do it with org2ogr. Use -dsco COORDINATE_PRECISION=2 as documented
in https://gdal.org/drivers/vector/geojson.html.

ogr2ogr -f geojson -dialect SQLite -sql "select
ScaleCoordinates(geometry,0.0254) from empty where geometry is not null"
round.json -lco coordinate_precision=2 empty.jml

Did I pass the test?

Recommended reading
http://www.gaia-gis.it/gaia-sins/spatialite-sql-latest.html

-Jukka Rahkonen-







Brandon Biggs wrote
> Hello,
> This doesn't seem to work. Thank you for the SQL link.
> I am wondering if these warnings have anything to do with the null
> geometries?





--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html


More information about the gdal-dev mailing list