Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm projecting some features using json format on OpenLayers. I need to get the id from the feature (not the OpenLayers' id but the one in the json file). The file looks something like this.

{"type": "FeatureCollection","features": [{ "type": "Feature", "id": 7655199, "properties": {"power":"line","wires":"NA","frequency":"NA","voltage":"380000","operator":"NA","cables":"6"}, "geometry": {"type":"LineString", "coordinates":[[8.5310699,49.8531139],[8.5289255,49.8563936],[8.5268405,49.8594383]]}} etc..

Now in OpenLayers I'm trying to do something like this.

var feature_col = gjson.read(ReadFile(json_path + file[i]) , "FeatureCollection");
//Readfile is just a function for reading the file, what a surprise... :P
var power_res = feature_col[0].attributes.power;
var id_res = feature_col[0].id) //for the first feature

So the value in power_res gives line which is correct. However, the value in id_res is something like OpenLayers.Feature.Vector_362 and I need the id in this case to be 7655199.

Thanks!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Try to use var id_res = feature_col[0].attributes.id instead var id_res = feature_col[0].id.

UPDATE

feature_col[0].fid See my live example here.

share|improve this answer
    
It doesn't work. It is undefined. Thanks anyway –  JPM Jul 16 '12 at 5:34
    
I've modified my answer, check it out. –  drnextgis Jul 16 '12 at 5:55

Ok, I found it. feature_col[0].fid is the way. It results into 7655199. FID not ID.

source: http://chitraswiki.blogspot.de/2009/11/getting-attributes-of.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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