2

I am writing a web service which in return gives json format data can anyone help me to convert this data into geojson format.

{
 "STATE_ABBR": "AK",
"file_name": "addresses",
"AREA_WATER": "2.45383480336E11",
"AREA_LAND": "1.47795321158E12",
"loc_address": "Kenai Spur Hwy, Kenai, AK 99611, USA",
"STATE_NAME": "Alaska",
"PERSONS": "710231",
"address_type": "church",
"MALE": "369628",
"location_type": "GEOMETRIC_CENTER",
"loc_lng": "-151.1820715",
"loc_name": "Kenai Fellowship",
"FEMALE": "340603",
"loc_id": "10672"
}
4
  • 3
    Just add coordinates
    – Ian Turton
    Commented Feb 19, 2016 at 7:32
  • Here is the link to the specification. Your JSON there would be the properties object of a feature. You'll have to figure out where and how to get the coordinates for whatever type of data you have there. But it's really not hard. When you have a more specific question I'd propose you make a new question for that ...
    – Frank
    Commented Feb 19, 2016 at 7:55
  • 4
    Where is second coordinates? I see only 'loc_lng'
    – user7172
    Commented Feb 19, 2016 at 8:06
  • ogre.adc4gis.com
    – MDHald
    Commented Feb 19, 2016 at 16:34

1 Answer 1

3

As in comments: Just add coordinates.

inJson['loc_lng'] it is doubled! (I see only one coordinates.)

For example:

var inJson = {
    "STATE_ABBR": "AK",
    "file_name": "addresses",
    "AREA_WATER": "2.45383480336E11",
    "AREA_LAND": "1.47795321158E12",
    "loc_address": "Kenai Spur Hwy, Kenai, AK 99611, USA",
    "STATE_NAME": "Alaska",
    "PERSONS": "710231",
    "address_type": "church",
    "MALE": "369628",
    "location_type": "GEOMETRIC_CENTER",
    "loc_lng": "-151.1820715",
    "loc_name": "Kenai Fellowship",
    "FEMALE": "340603",
    "loc_id": "10672"
}

var outGeoJson = {}
outGeoJson['properties'] = inJson
outGeoJson['type']= "Feature"
outGeoJson['geometry']= {"type": "Point", "coordinates":
    [inJson['loc_lng'], inJson['loc_lng']]}

console.log(outGeoJson)

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.