Posts

Showing posts with the label kml

How to convert kml to shape format throught ogr2ogr

You can create your kml file online with scribblemaps  and download it to your computer. If you create lines and markers in the same file, you will get this error: ogr2ogr -f "ESRI Shapefile" file.shp file.kml -skipfailures Warning 6: Normalized/laundered field name: 'description' to 'descriptio' Warning 6: Field timestamp create as date field, though DateTime requested. Warning 6: Field begin create as date field, though DateTime requested. Warning 6: Field end create as date field, though DateTime requested. Warning 6: Normalized/laundered field name: 'altitudeMode' to 'altitudeMo' ERROR 1: Attempt to write non-point (LINESTRING) geometry to point shapefile. ERROR 1: Attempt to write non-point (LINESTRING) geometry to point shapefile. ERROR 1: Attempt to write non-point (LINESTRING) geometry to point shapefile. To avoid it, you must create separated files for points, linestring or polygon as: ogr2ogr point.shp point.kml -skipfa...

Load kml geojson osm shp files in Postgis

In my last post I talk how to convert from kml to GeoJson Now, I want to load this file in a Spatial and Geographic Objects for PostgreSQL (postgis) I read in many sites that you can convert from osm 2 postgres, then I will try to convert to osm file with geojsontoosm. # sudo  npm install -g geojsontoosm npm ERR! enoent ENOENT: no such file or directory, open '/tmp/npm-15537-43d2f472/unpack-edff7974/package.json' npm ERR! enoent ENOENT: no such file or directory, open '/tmp/npm-15537-43d2f472/unpack-edff7974/package.json' npm ERR! enoent This is most likely not a problem with npm itself npm ERR! enoent and is related to npm not being able to find a file. npm ERR! enoent  To install, I used the git files: # git clone https://github.com/tyrasd/geojsontoosm.git # cd geojsontoosm # ./geojsontoosm  module.js:471     throw err;     ^ Error: Cannot find module 'jxon' Error: Cannot find module 'optimist' Error: Cannot find module 'geo...

How to convert from kml to GeoJson with python3

To do it, you can import ogr from osgeo from osgeo import ogr def kml2geojson(kml_file):     drv = ogr.GetDriverByName('KML')     kml_ds = drv.Open(kml_file)     for kml_lyr in kml_ds:         for feat in kml_lyr:             print feat.ExportToJson() kml2geojson('/path/to/your.kml') But, if you try to run it, maybe you will see the following error: ImportError: No module named 'osgeo' This means that you need gdal libraries. If you try to install it with pip3 you will see the following: pip3 install gdal ... cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++     extensions/gdal_wrap.cpp:3168:22: fatal error: cpl_port.h: No such file or directory     compilation terminated.     error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 We search which pakage includes cpl_port.h: apt-file search cpl_por...