Re: [OpenLayers-Users] Make vector layer from JSON

2010-03-08 Thread Sveen Atle Frenvik (Geomatikk IKT)
As long as you are able to parse the data, putting them on the map is a 
no-brainer, pseudo-code something like:

for each feature
 - fetch x and y
 - create an OpenLayers Geometry
 - create a OpenLayers Vector feature
 - add attributes to feature if required

then add features to a layer

-atle

On 03/08/2010 01:19 AM, Stephen Woodbridge wrote:
 Hi Guys,

 I have been looking into a similar problem using some arbitrary XML and
 have some questions on how to do this also that I will post in a
 separate thread, but here is my take on what needs to be done.

 OpenLayers.Format.JSON should handle the actual parsing and give you a
 top level variable for the obj.

 I think what you need to do is implement your own read function or
 callback, that should get the parsed JSON file and then you create the
 features and add them to the layer.

 So this is all in theory at the moment, because I haven't been able to
 figure out the exact steps for doing it in my own project. But since I
 have looked at a similar problem all day I think this is the approach.

 So I think in your code below you need to do something like:

var data = json.read(resp);
var features = myMakeFeatures(data);

 then add the features to the layer.

 -Steve W.

 Arnd Wippermann wrote:

 Hello Robert,

 I don't know ArcGis Server, but I would look, if you can get your data
 in gml or kml. Otherwise you have to write your own parser.

 Arnd

 
 *Von:* Robert Sanson [mailto:sans...@asurequality.com]
 *Gesendet:* Sonntag, 7. M�rz 2010 21:09
 *An:* 'Hugo'; Arnd Wippermann
 *Cc:* users@openlayers.org
 *Betreff:* Re: [OpenLayers-Users] Make vector layer from JSON

 I am wrestling with a similar problem. I am trying to read in data
 coming from an ArcGIS Server in JSON format. Unfortunately, ArcGIS
 Server doesn't serve GeoJSON. Here is a sample of what the data looks like:

 {
results : [
  {
layerId : 0,
layerName : Main_Gates,
displayFieldName : road_name,
foundFieldName : farm_id,
value : AS00136,
attributes : {
  point_location_id : 232495,
  farm_id : AS00136,
  rapid_no : 104,
  road_name : Winslow Willowby Rd,
  locality : Null,
  x_nztm : 1492934.61,
  y_nztm : 5131545.29,
  Shape : Point
},
geometryType : esriGeometryPoint,
geometry :
{
  x : 1492934.61,
  y : 5131545.29,
  spatialReference : {
wkid : 2193
  }
}
  }
]
 }
 Any ideas how to get OL to read this into a Vector layer?

 Thanks,

 Robert
 Arnd Wippermannarnd.wipperm...@web.de  7/03/2010 10:43 a.m.
 Hi,
 i would think, that you have to use geojson instead of json, to get the
 geometry for the features.
 Arnd

 
 *Von:* users-boun...@openlayers.org
 [mailto:users-boun...@openlayers.org] *Im Auftrag von *Hugo
 *Gesendet:* Samstag, 6. M�rz 2010 19:14
 *An:* openlayers
 *Betreff:* [OpenLayers-Users] Make vector layer from JSON

 Hello all,

 I'm trying to create a vector layer based on a php query (which includes
 the_geom) encoded in JSON. Until the moment i haven't been able to
 achieve this.
 Following, is the relevant part of the code:

 var connect = new Ext.data.Connection();
 connect.request({
  url: 'mfbase/geoquery.php',
  params: {
  species: species,
  datai: datai,
  dataf: dataf
  },
  success: function(response){
  var resp = response.responseText;
  var json = new OpenLayers.Format.JSON();
  var data = json.read(resp);
  //console.log(data[0].the_geom);

  var querylayer1 = new OpenLayers.Layer.Vector(
  'Query1',
  {
  isBaseLayer: false,
  projection: wgs,
  geometryName: 'the_geom',
  }
  );

  querylayer1.addFeatures(data);
  map.addLayer(querylayer1);
  }
 })

 Any suggestions are more than welcomed :)
 Thanks to you all!

 Cheers,


 -- 
 Hugo Martins
 FMV-UTL
 CIISA-Epidemiologia e Sa�de P�blica Veterin�ria
 Av. da Universidade T�cnica
 1300-477 Lisboa
 N 38�42'49.54, W 9�11'43.42


 Click herehttps://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg==  to
 report this email as spam.




 --
 The contents of this email are confidential to AsureQuality. If you have 
 received this communication in error please notify the sender immediately 
 and delete the message and any attachments. The opinions expressed in this 
 email are not necessarily those of AsureQuality. This message has been 
 scanned for known viruses before delivery. AsureQuality supports the 
 Unsolicited Electronic Messages Act 2007. If you

Re: [OpenLayers-Users] Make vector layer from JSON

2010-03-08 Thread Eric Lemoine
On Saturday, March 6, 2010, Hugo hfpmart...@gmail.com wrote:
 Hello all,

 I'm trying to create a vector layer based on a php query (which includes 
 the_geom) encoded in JSON. Until the moment i haven't been able to achieve 
 this.
 Following, is the relevant part of the code:

 var connect = new Ext.data.Connection();
 connect.request({
     url: 'mfbase/geoquery.php',
     params: {
         species: species,
         datai: datai,
         dataf: dataf
     },
     success: function(response){
         var resp = response.responseText;
         var json = new OpenLayers.Format.JSON();
         var data = json.read(resp);
         //console.log(data[0].the_geom);

         var querylayer1 = new OpenLayers.Layer.Vector(
             'Query1',
             {
                 isBaseLayer: false,
                 projection: wgs,
                 geometryName: 'the_geom',
             }
         );

         querylayer1.addFeatures(data);

addFeatures should receive an array of OpenLayers.Feature.Vector objects.

How are geometries encoded in your JSON responses? If they are encoded
as WKT you will also need OpenLayers.Format.WKT.

Have you considered using GeoJSON? Using GeoJSON your client code will
be simpler.

Cheers,

         map.addLayer(querylayer1);
     }
 })
 Any suggestions are more than welcomed :)
 Thanks to you all!

 Cheers,


 --
 Hugo Martins
 FMV-UTL
 CIISA-Epidemiologia e Saúde Pública Veterinária
 Av. da Universidade Técnica
 1300-477 Lisboa
 N 38°42'49.54, W 9°11'43.42


-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemo...@camptocamp.com
http://www.camptocamp.com
___
Users mailing list
Users@openlayers.org
http://openlayers.org/mailman/listinfo/users


Re: [OpenLayers-Users] Make vector layer from JSON

2010-03-08 Thread Hugo
Thanks a lot for all the inputs you have given.
In fact with GeoJSON everything goes smoothly.

Cheers,
Hugo

On Mon, Mar 8, 2010 at 7:20 PM, Eric Lemoine eric.lemo...@camptocamp.comwrote:

 On Saturday, March 6, 2010, Hugo hfpmart...@gmail.com wrote:
  Hello all,
 
  I'm trying to create a vector layer based on a php query (which includes
 the_geom) encoded in JSON. Until the moment i haven't been able to achieve
 this.
  Following, is the relevant part of the code:
 
  var connect = new Ext.data.Connection();
  connect.request({
  url: 'mfbase/geoquery.php',
  params: {
  species: species,
  datai: datai,
  dataf: dataf
  },
  success: function(response){
  var resp = response.responseText;
  var json = new OpenLayers.Format.JSON();
  var data = json.read(resp);
  //console.log(data[0].the_geom);
 
  var querylayer1 = new OpenLayers.Layer.Vector(
  'Query1',
  {
  isBaseLayer: false,
  projection: wgs,
  geometryName: 'the_geom',
  }
  );
 
  querylayer1.addFeatures(data);

 addFeatures should receive an array of OpenLayers.Feature.Vector objects.

 How are geometries encoded in your JSON responses? If they are encoded
 as WKT you will also need OpenLayers.Format.WKT.

 Have you considered using GeoJSON? Using GeoJSON your client code will
 be simpler.

 Cheers,

  map.addLayer(querylayer1);
  }
  })
  Any suggestions are more than welcomed :)
  Thanks to you all!
 
  Cheers,
 
 
  --
  Hugo Martins
  FMV-UTL
  CIISA-Epidemiologia e Saúde Pública Veterinária
  Av. da Universidade Técnica
  1300-477 Lisboa
  N 38°42'49.54, W 9°11'43.42
 

 --
 Eric Lemoine

 Camptocamp France SAS
 Savoie Technolac, BP 352
 73377 Le Bourget du Lac, Cedex

 Tel : 00 33 4 79 44 44 96
 Mail : eric.lemo...@camptocamp.com
 http://www.camptocamp.com




-- 
Hugo Martins
FMV-UTL
CIISA-Epidemiologia e Saúde Pública Veterinária
Av. da Universidade Técnica
1300-477 Lisboa
N 38°42'49.54, W 9°11'43.42
___
Users mailing list
Users@openlayers.org
http://openlayers.org/mailman/listinfo/users


Re: [OpenLayers-Users] Make vector layer from JSON

2010-03-07 Thread Robert Sanson
I am wrestling with a similar problem. I am trying to read in data
coming from an ArcGIS Server in JSON format. Unfortunately, ArcGIS
Server doesn't serve GeoJSON. Here is a sample of what the data looks
like:
 
{
  results : [
{
  layerId : 0, 
  layerName : Main_Gates, 
  displayFieldName : road_name, 
  foundFieldName : farm_id, 
  value : AS00136, 
  attributes : {
point_location_id : 232495, 
farm_id : AS00136, 
rapid_no : 104, 
road_name : Winslow Willowby Rd, 
locality : Null, 
x_nztm : 1492934.61, 
y_nztm : 5131545.29, 
Shape : Point
  }, 
  geometryType : esriGeometryPoint, 
  geometry : 
  {
x : 1492934.61, 
y : 5131545.29, 
spatialReference : {
  wkid : 2193
}
  }
}
  ]
}
Any ideas how to get OL to read this into a Vector layer?
 
Thanks,
 
Robert
 Arnd Wippermann arnd.wipperm...@web.de 7/03/2010 10:43 a.m.

Hi,

i would think, that you have to use geojson instead of json, to get the
geometry for the features.

Arnd

Von: users-boun...@openlayers.org [mailto:users-boun...@openlayers.org]
Im Auftrag von Hugo
Gesendet: Samstag, 6. März 2010 19:14
An: openlayers
Betreff: [OpenLayers-Users] Make vector layer from JSON

Hello all,

I'm trying to create a vector layer based on a php query (which
includes the_geom) encoded in JSON. Until the moment i haven't been able
to achieve this.
Following, is the relevant part of the code:

var connect = new Ext.data.Connection();
connect.request({
url: 'mfbase/geoquery.php',
params: {
species: species,
datai: datai,
dataf: dataf
},
success: function(response){
var resp = response.responseText;
var json = new OpenLayers.Format.JSON();
var data = json.read(resp);
//console.log(data[0].the_geom);

var querylayer1 = new OpenLayers.Layer.Vector(
'Query1',
{
isBaseLayer: false,
projection: wgs,
geometryName: 'the_geom',
}
);

querylayer1.addFeatures(data);
map.addLayer(querylayer1);
}
})

Any suggestions are more than welcomed :)
Thanks to you all!

Cheers,


-- 
Hugo Martins
FMV-UTL
CIISA-Epidemiologia e Saúde Pública Veterinária
Av. da Universidade Técnica
1300-477 Lisboa
N 38*42'49.54, W 9*11'43.42



Click here (
https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg==
) to report this email as spam.
--
The contents of this email are confidential to AsureQuality. If you have 
received this communication in error please notify the sender immediately and 
delete the message and any attachments. The opinions expressed in this email 
are not necessarily those of AsureQuality. This message has been scanned for 
known viruses before delivery. AsureQuality supports the Unsolicited Electronic 
Messages Act 2007. If you do not wish to receive similar communications in 
future, please notify the sender of this message.
--


This message has been scanned for malware by SurfControl plc. 
www.surfcontrol.com
___
Users mailing list
Users@openlayers.org
http://openlayers.org/mailman/listinfo/users


Re: [OpenLayers-Users] Make vector layer from JSON

2010-03-07 Thread Arnd Wippermann
Hello Robert,
 
I don't know ArcGis Server, but I would look, if you can get your data in
gml or kml. Otherwise you have to write your own parser.
 
Arnd

  _  

Von: Robert Sanson [mailto:sans...@asurequality.com] 
Gesendet: Sonntag, 7. März 2010 21:09
An: 'Hugo'; Arnd Wippermann
Cc: users@openlayers.org
Betreff: Re: [OpenLayers-Users] Make vector layer from JSON


I am wrestling with a similar problem. I am trying to read in data coming
from an ArcGIS Server in JSON format. Unfortunately, ArcGIS Server doesn't
serve GeoJSON. Here is a sample of what the data looks like:
 
{
  results : [
{
  layerId : 0, 
  layerName : Main_Gates, 
  displayFieldName : road_name, 
  foundFieldName : farm_id, 
  value : AS00136, 
  attributes : {
point_location_id : 232495, 
farm_id : AS00136, 
rapid_no : 104, 
road_name : Winslow Willowby Rd, 
locality : Null, 
x_nztm : 1492934.61, 
y_nztm : 5131545.29, 
Shape : Point
  }, 
  geometryType : esriGeometryPoint, 
  geometry : 
  {
x : 1492934.61, 
y : 5131545.29, 
spatialReference : {
  wkid : 2193
}
  }
}
  ]
}

Any ideas how to get OL to read this into a Vector layer?
 
Thanks,
 
Robert
 Arnd Wippermann arnd.wipperm...@web.de 7/03/2010 10:43 a.m. 

Hi,
i would think, that you have to use geojson instead of json, to get the
geometry for the features.
Arnd

  _  

Von: users-boun...@openlayers.org [mailto:users-boun...@openlayers.org] Im
Auftrag von Hugo
Gesendet: Samstag, 6. März 2010 19:14
An: openlayers
Betreff: [OpenLayers-Users] Make vector layer from JSON


Hello all,

I'm trying to create a vector layer based on a php query (which includes
the_geom) encoded in JSON. Until the moment i haven't been able to achieve
this.
Following, is the relevant part of the code:

var connect = new Ext.data.Connection();
connect.request({
url: 'mfbase/geoquery.php',
params: {
species: species,
datai: datai,
dataf: dataf
},
success: function(response){
var resp = response.responseText;
var json = new OpenLayers.Format.JSON();
var data = json.read(resp);
//console.log(data[0].the_geom);

var querylayer1 = new OpenLayers.Layer.Vector(
'Query1',
{
isBaseLayer: false,
projection: wgs,
geometryName: 'the_geom',
}
);

querylayer1.addFeatures(data);
map.addLayer(querylayer1);
}
})

Any suggestions are more than welcomed :)
Thanks to you all!

Cheers,


-- 
Hugo Martins
FMV-UTL
CIISA-Epidemiologia e Saúde Pública Veterinária
Av. da Universidade Técnica
1300-477 Lisboa
N 38°42'49.54, W 9°11'43.42




Click here https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg==  to
report this email as spam.




--
The contents of this email are confidential to AsureQuality. If you have
received this communication in error please notify the sender immediately
and delete the message and any attachments. The opinions expressed in this
email are not necessarily those of AsureQuality. This message has been
scanned for known viruses before delivery. AsureQuality supports the
Unsolicited Electronic Messages Act 2007. If you do not wish to receive
similar communications in future, please notify the sender of this message.
--  



This message has been scanned for malware by SurfControl plc.
http://www.surfcontrol.com/ www.surfcontrol.com

___
Users mailing list
Users@openlayers.org
http://openlayers.org/mailman/listinfo/users


Re: [OpenLayers-Users] Make vector layer from JSON

2010-03-07 Thread Stephen Woodbridge
Hi Guys,

I have been looking into a similar problem using some arbitrary XML and 
have some questions on how to do this also that I will post in a 
separate thread, but here is my take on what needs to be done.

OpenLayers.Format.JSON should handle the actual parsing and give you a 
top level variable for the obj.

I think what you need to do is implement your own read function or 
callback, that should get the parsed JSON file and then you create the 
features and add them to the layer.

So this is all in theory at the moment, because I haven't been able to 
figure out the exact steps for doing it in my own project. But since I 
have looked at a similar problem all day I think this is the approach.

So I think in your code below you need to do something like:

  var data = json.read(resp);
  var features = myMakeFeatures(data);

then add the features to the layer.

-Steve W.

Arnd Wippermann wrote:
 Hello Robert,
  
 I don't know ArcGis Server, but I would look, if you can get your data 
 in gml or kml. Otherwise you have to write your own parser.
  
 Arnd
 
 
 *Von:* Robert Sanson [mailto:sans...@asurequality.com]
 *Gesendet:* Sonntag, 7. März 2010 21:09
 *An:* 'Hugo'; Arnd Wippermann
 *Cc:* users@openlayers.org
 *Betreff:* Re: [OpenLayers-Users] Make vector layer from JSON
 
 I am wrestling with a similar problem. I am trying to read in data 
 coming from an ArcGIS Server in JSON format. Unfortunately, ArcGIS 
 Server doesn't serve GeoJSON. Here is a sample of what the data looks like:
  
 {
   results : [
 {
   layerId : 0,
   layerName : Main_Gates,
   displayFieldName : road_name,
   foundFieldName : farm_id,
   value : AS00136,
   attributes : {
 point_location_id : 232495,
 farm_id : AS00136,
 rapid_no : 104,
 road_name : Winslow Willowby Rd,
 locality : Null,
 x_nztm : 1492934.61,
 y_nztm : 5131545.29,
 Shape : Point
   },
   geometryType : esriGeometryPoint,
   geometry :
   {
 x : 1492934.61,
 y : 5131545.29,
 spatialReference : {
   wkid : 2193
 }
   }
 }
   ]
 }
 Any ideas how to get OL to read this into a Vector layer?
  
 Thanks,
  
 Robert
   Arnd Wippermann arnd.wipperm...@web.de 7/03/2010 10:43 a.m. 
 Hi,
 i would think, that you have to use geojson instead of json, to get the 
 geometry for the features.
 Arnd
 
 
 *Von:* users-boun...@openlayers.org 
 [mailto:users-boun...@openlayers.org] *Im Auftrag von *Hugo
 *Gesendet:* Samstag, 6. März 2010 19:14
 *An:* openlayers
 *Betreff:* [OpenLayers-Users] Make vector layer from JSON
 
 Hello all,
 
 I'm trying to create a vector layer based on a php query (which includes 
 the_geom) encoded in JSON. Until the moment i haven't been able to 
 achieve this.
 Following, is the relevant part of the code:
 
 var connect = new Ext.data.Connection();
 connect.request({
 url: 'mfbase/geoquery.php',
 params: {
 species: species,
 datai: datai,
 dataf: dataf
 },
 success: function(response){
 var resp = response.responseText;
 var json = new OpenLayers.Format.JSON();
 var data = json.read(resp);
 //console.log(data[0].the_geom);

 var querylayer1 = new OpenLayers.Layer.Vector(
 'Query1',
 {
 isBaseLayer: false,
 projection: wgs,
 geometryName: 'the_geom',
 }
 );

 querylayer1.addFeatures(data);
 map.addLayer(querylayer1);
 }
 })
 
 Any suggestions are more than welcomed :)
 Thanks to you all!
 
 Cheers,
 
 
 -- 
 Hugo Martins
 FMV-UTL
 CIISA-Epidemiologia e Saúde Pública Veterinária
 Av. da Universidade Técnica
 1300-477 Lisboa
 N 38°42'49.54, W 9°11'43.42
 
 
 Click here https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg== to 
 report this email as spam.
 
 
 
 
 --
 The contents of this email are confidential to AsureQuality. If you have 
 received this communication in error please notify the sender immediately and 
 delete the message and any attachments. The opinions expressed in this email 
 are not necessarily those of AsureQuality. This message has been scanned for 
 known viruses before delivery. AsureQuality supports the Unsolicited 
 Electronic Messages Act 2007. If you do not wish to receive similar 
 communications in future, please notify the sender of this message.
 --
 
 
 
 This message has been scanned for malware by SurfControl plc. 
 www.surfcontrol.com http://www.surfcontrol.com

[OpenLayers-Users] Make vector layer from JSON

2010-03-06 Thread Hugo
Hello all,

I'm trying to create a vector layer based on a php query (which includes
the_geom) encoded in JSON. Until the moment i haven't been able to achieve
this.
Following, is the relevant part of the code:

var connect = new Ext.data.Connection();
connect.request({
url: 'mfbase/geoquery.php',
params: {
species: species,
datai: datai,
dataf: dataf
},
success: function(response){
var resp = response.responseText;
var json = new OpenLayers.Format.JSON();
var data = json.read(resp);
//console.log(data[0].the_geom);

var querylayer1 = new OpenLayers.Layer.Vector(
'Query1',
{
isBaseLayer: false,
projection: wgs,
geometryName: 'the_geom',
}
);

querylayer1.addFeatures(data);
map.addLayer(querylayer1);
}
})

Any suggestions are more than welcomed :)
Thanks to you all!

Cheers,


-- 
Hugo Martins
FMV-UTL
CIISA-Epidemiologia e Saúde Pública Veterinária
Av. da Universidade Técnica
1300-477 Lisboa
N 38°42'49.54, W 9°11'43.42
___
Users mailing list
Users@openlayers.org
http://openlayers.org/mailman/listinfo/users


Re: [OpenLayers-Users] Make vector layer from JSON

2010-03-06 Thread Arnd Wippermann
Hi,
 
i would think, that you have to use geojson instead of json, to get the
geometry for the features.
 
Arnd

  _  

Von: users-boun...@openlayers.org [mailto:users-boun...@openlayers.org] Im
Auftrag von Hugo
Gesendet: Samstag, 6. März 2010 19:14
An: openlayers
Betreff: [OpenLayers-Users] Make vector layer from JSON


Hello all,

I'm trying to create a vector layer based on a php query (which includes
the_geom) encoded in JSON. Until the moment i haven't been able to achieve
this.
Following, is the relevant part of the code:

var connect = new Ext.data.Connection();
connect.request({
url: 'mfbase/geoquery.php',
params: {
species: species,
datai: datai,
dataf: dataf
},
success: function(response){
var resp = response.responseText;
var json = new OpenLayers.Format.JSON();
var data = json.read(resp);
//console.log(data[0].the_geom);

var querylayer1 = new OpenLayers.Layer.Vector(
'Query1',
{
isBaseLayer: false,
projection: wgs,
geometryName: 'the_geom',
}
);

querylayer1.addFeatures(data);
map.addLayer(querylayer1);
}
})

Any suggestions are more than welcomed :)
Thanks to you all!

Cheers,


-- 
Hugo Martins
FMV-UTL
CIISA-Epidemiologia e Saúde Pública Veterinária
Av. da Universidade Técnica
1300-477 Lisboa
N 38°42'49.54, W 9°11'43.42

___
Users mailing list
Users@openlayers.org
http://openlayers.org/mailman/listinfo/users