2

I am trying to convert a GeoJSON file into an SQLite database and I want to set to INTEGER a specific field in the SQLite final file.

I use the following command line:

ogr2ogr -f SQLite -mapFieldType my_field=Integer final_file.sqlite source_file.geojson

But as a result I get an error:

ERROR 5: Invalid value for -mapFieldType : my_field=Integer

Without the mapFieldType option it works well. I used the example shown in the GDAL wiki https://trac.osgeo.org/gdal/wiki/rfc31_ogr_64

0

2 Answers 2

5

You seem to have misunderstood how -mapFieldType works, from the manual

-mapFieldType srctype|All=dsttype, ...: (starting with GDAL 2.0) converts any field of the specified type to another type. Valid types are : Integer, Integer64, Real, String, Date, Time, DateTime, Binary, IntegerList, Integer64List, RealList, StringList. Types can also include subtype between parenthesis, such as Integer(Boolean), Real(Float32), ... Special value All can be used to convert all fields to another type. This is an alternate way to using the CAST operator of OGR SQL, that may avoid typing a long SQL query. This is a generalization of -fieldTypeToString. Note that this does not influence the field types used by the source driver, and is only an afterwards conversion.

I've added emphasis to the relevant section, you need to specify two types and the program converts all fields of the 1st type to the 2nd. This section also hints that you may be able to achieve what you want using a cast in an SQL statement passed in using -sql.

2

This code convert all schema data types int:11 (Integer64) to Real type in data.shp

ogr2ogr -f "FileGDB" -update -overwrite test.gdb -mapFieldType Integer64=Real data.shp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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