[Geojson] Adding extra data to a geojson string

Chitraleka Appalanaidu achitraleka at gmail.com
Sun Nov 1 19:51:39 PST 2009


A more detailed initial background to this issue is here:
http://chitraswiki.blogspot.com/2009/11/getting-attributes-of.html


On Mon, Nov 2, 2009 at 2:35 PM, Chitraleka Appalanaidu <
achitraleka at gmail.com> wrote:

> Hi Tim,
>
> Thank you very much for your help. feature.cluster solved the problem.
>
> For other users who come across this problem, try to get the attributes of
> a point (specified in the geojson file in the 'properties' list) by using
> feature.cluster[0].attributes.<name_of_attribute_key>
>
> {
>    "type": "FeatureCollection",
>    "features": [
>        {"type":"Feature", "id":"computer1", "properties":{"trial":"test"},
> "geometry":{"type":"Point", "coordinates":[143, -35.91]}},
>        {"type":"Feature", "id":"computer2", "properties":{"trial":"test"},
> "geometry":{"type":"Point", "coordinates":[144, -37.81667]}}
>    ]
> }
>
> Basically, this is what happens when the geojson fileabove is parsed by
> OpenLayers.Format.GeoJSON parser and added as OpenLayers.Vector.Feature
> objects into a OpenLayers Vector layer (that performs the clustering
> strategy):
> 1. GeoJSON file is read by the GeoJSON parser.
> 2. Parser creates OpenLayers.Vector.Feature objects for each string.
> 3. These OpenLayers.Vector.Feature objects are then added to the OpenLayers
> Vector layer
> 4. OpenLayers Vector layer performs clustering strategy
> 5. Each feature point that appears on the map is the top-level feature
> point (for a group of clusters). The attributes for this feature point is:
>
> undefinedlayer value :[object Object]
>  lonlat value :null
>  data value :[object Object]
>  id value :OpenLayers.Feature.Vector_201
>  geometry value :POINT(15918687.18122222 -4288244.5663272375)
>  state value :null
>  attributes value :[object Object]
>  style value :null
>  cluster value :[object Object],[object Object],[object Object]
> //this indicates that this cluster point has three feature objects
> underneath it
>  renderIntent value :select
>  marker value :null
>
> 6. As it can be seen above, there is a 'cluster' property that holds 3
> objects (being the three points). Hence, if you drill down to the 'cluster'
> property (i.e. feature.cluster[0]), it will give you the attributes of the
> first object in the cluster (being the point):
>
> undefined0 value :[object Object]
>  layer value :null
>  lonlat value :null
>  data value :[object Object]
>  id value :OpenLayers.Feature.Vector_197
>  geometry value :POINT(8218510.393273033 -2699238.272071229)
>  state value :null
>  attributes value :[object Object]
>  style value :null
>  fid value :computer14
>  marker value :null
>
> 7. From the above, it can be seen that the 'id' property from the geojson
> file has been mapped to the 'fid' key of the feature point object. You can
> also see that the 'attributes' key holds an [object Object]. If you do
> feature.cluster[0].attributes.trial , it will display the 'trial' property
> and value that you specified in the geojson file (i.e. 'test').
>
>
> Hence, adding as many property-value pairs in the GeoJSON file is easy as
> the GeoJSON parser just parsers the property-value pairs and enters the data
> into feature point object attributes that are beneath the top-level cluster
> point.
>
> Kind regards,
> Chitra
>
>
>
> On Mon, Nov 2, 2009 at 12:56 PM, Tim Schaub <tschaub at opengeo.org> wrote:
>
>> Hey-
>>
>>
>> Chitraleka Appalanaidu wrote:
>>
>>> Hi all,
>>>
>>> I have a geojson file that I pass to the penLayers.Format.GeoJSON parser.
>>> This parser converts the a geojson string (as below) to a
>>> OpenLayers.Vector.Feature object and adds it into an OpenLayers Vector layer
>>> (that performs clustering)
>>>
>>> {
>>>    "type": "FeatureCollection",
>>>    "features": [
>>>        {"type":"Feature", "id":"computer1",
>>> "properties":{"trial":"test"}, "geometry":{"type":"Point",
>>> "coordinates":[143, -35.91]}},
>>>        {"type":"Feature", "id":"computer2",
>>> "properties":{"trial":"test"}, "geometry":{"type":"Point",
>>> "coordinates":[144, -37.81667]}}
>>>
>>>    ]
>>> }
>>>
>>>
>>> The problem with adding it into a clustering layer is that any properties
>>> I add into the "properties":{} field in the above geojson file will get
>>> overriden (because clustering will cause a count value to be entered into
>>> the properties list).
>>>
>>> I would like to add other information about a point in the geojson file
>>> above. Is there any other key-value pair i can use to do this? I have tried
>>> the 'fid' and 'style' key-value pairs but the parser does not seem to parse
>>> them out into a OpenLayers.Vector.Feature object.
>>>
>>>
>> In terms of what you can do in GeoJSON, any other members (with
>> non-reserved names) are allowed on feature objects.
>>
>> I think your issue is exclusively an OpenLayers issue.  OpenLayers will
>> parse whatever you put in the properties member and make this available at
>> feature.attributes (as you've seen).  When you use the cluster strategy, you
>> can get at the original features in the cluster via feature.cluster.
>>
>> If you haven't already, you could write an email to the OpenLayers dev
>> list with more specific questions.
>>
>> Tim
>>
>>  Thank you.
>>>
>>> Kind regards,
>>> Chitra
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Geojson mailing list
>>> Geojson at lists.geojson.org
>>> http://lists.geojson.org/listinfo.cgi/geojson-geojson.org
>>>
>>
>>
>> --
>> Tim Schaub
>> OpenGeo - http://opengeo.org
>> Expert service straight from the developers.
>> _______________________________________________
>> Geojson mailing list
>> Geojson at lists.geojson.org
>> http://lists.geojson.org/listinfo.cgi/geojson-geojson.org
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.geojson.org/pipermail/geojson-geojson.org/attachments/20091102/017f73ad/attachment.htm>


More information about the GeoJSON mailing list