2

I am looking for the fastest way to convert WKT or geojson geometry from string to numpy array of coordinates.

Is it possible to do it strictly in Python and without creating geometry object such Shapely shape, OGRGeometry or GEOSGeometry?

2

Converting GeoJson to numpy array seems to be much easier than trying to convert WKT to numpy array.

import numpy as np
import json

#if your geojson is a string
geoJson = json.load(geoJsonString)

numpy_array = np.array(geoJson['coordinates'])

and back to geojson:

geoJson['coordinates'] = numpy_array.tolist()

#if you are looking for string geojson
geoJsonString = json.dumps(geoJson)

That's all for geojson. Please answer the question if you have a solution for WKT

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.