Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 = + 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.


share|improve this question
up vote 2 down vote accepted

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


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

share|improve this answer
It doesn't work. It is undefined. Thanks anyway – zom-pro 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.


share|improve this answer

Your Answer


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.