0

I have several fields in a json file, and I need to determine which of the json-fields are GeoJSON. For example, here is a sample of the data I have:

{
    "name": "bob",
    "age": 20,
    "info": {"height": 189, "weight": 101}
    "location": { "type": "Feature","geometry": {"type": "Point","coordinates": [125.6, 10.1]},"properties": {"name": "Dinagat Islands"}}
}

I would like to get the following column information from this:

  • name (string)
  • age (int)
  • info (json)
  • location (geojson)

What would be the best way to determine if a json object is actually a GeoJSON object? I've viewed various examples of GeoJSON, such as http://geojsonlint.com/ and it seems like it is quite flexible in how it can be specified.

Is there a sure-fire way to know whether a json object is GeoJSON or not?

David542
  • 104,438
  • 178
  • 489
  • 842

1 Answers1

0

You can use pandas to convert the json/geojson object into a dataframe. Link here.
Get location points using:

Install geopy.

pip install geopy

To get the location:

location = df['location']['geometry']['coordinates']

Then,

try:
   from geopy.geocoders import Nominatim
   geolocator = Nominatim(user_agent="specify_your_app_name_here")
   location = geolocator.reverse(str(location))
   print(location.address)
except:
   print('not GEOjson') #there will be exception if the coordinates don't represent a location

This based on the fact that coordinates are a pair and will give a location address.

Else:

You can just check if they have some features like coordinates or geometry then its geojson.

As the whole thing is in a dataframe, then it is easier to visualise and to use any value as you wish!!

You can also get name, location or anything else in the same way.

ASHu2
  • 2,027
  • 15
  • 29