[OpenLayers-Users] Problems parsing GML

David Alda Fernandez de Lezea dalda at ikt.es
Thu Nov 10 10:18:35 EST 2011


Hi list,

I'm developing a functionallity for an app that will allow the users to add GML, in version 3, files previously created in different GIS desktop software. So far I've tried with QGIS and gvSIG.

Using QGIS, I got an GML and I can parse and load it in OpenLayers, but with gvSIG not. Using gvSIG, once the data is parsed the geometry is set to null.


So basically my question could be how can I create a generic method to parse different GML files created from different sources?? Or what do I have to take into account to do so?? Namespaces??

My openlayers code:

var theParser = new OpenLayers.Format.GML();
theParser.internalProjection = null;
theParser.externalProjection = null;
theParser.extractStyles = false;
theParser.extractAttributes = true;
var features = theParser.read(req);

GML from QGIS

  <?xml version="1.0" encoding="utf-8" ?> 
 <ogr:FeatureCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ogr.maptools.org/ prueba.xsd" xmlns:ogr="http://ogr.maptools.org/" xmlns:gml="http://www.opengis.net/gml">
 <gml:boundedBy>
 <gml:Box>
 <gml:coord>
  <gml:X>509296.3493197768</gml:X> 
  <gml:Y>4754836.958233111</gml:Y> 
  </gml:coord>
 <gml:coord>
  <gml:X>518092.0880311229</gml:X> 
  <gml:Y>4763261.318750359</gml:Y> 
  </gml:coord>
  </gml:Box>
  </gml:boundedBy>
 <gml:featureMember>
 <ogr:prueba fid="F0">
 <ogr:geometryProperty>
 <gml:Polygon>
 <gml:outerBoundaryIs>
 <gml:LinearRing>
  <gml:coordinates>510483.09779106994,4763261.3187503591 509759.18122358114,4762311.9199733241 509747.31373886816,4762264.4500344731 509759.18122358114,4761647.3408294003 509438.75913633197,4761599.8708905485 509296.34931977681,4762442.4623051668 510483.09779106994,4763261.3187503591</gml:coordinates> 
  </gml:LinearRing>
  </gml:outerBoundaryIs>
  </gml:Polygon>
  </ogr:geometryProperty>
  <ogr:Campo1 /> 
  <ogr:Campo2 /> 
  <ogr:Campo3 /> 
  <ogr:Campo4 /> 
  <ogr:Campo5 /> 
  <ogr:Campo6 /> 
  <ogr:Campo7 /> 
  </ogr:prueba>
  </gml:featureMember>
 <gml:featureMember>
 <ogr:prueba fid="F1">
 <ogr:geometryProperty>
 <gml:Polygon>
 <gml:outerBoundaryIs>
 <gml:LinearRing>
  <gml:coordinates>518092.08803112287,4754865.0112195052 518086.47743384406,4754858.1538228309 518068.39884261234,4754853.7900249474 518044.0862544041,4754850.0496267611 518014.16306891706,4754838.205032506 517987.35688191827,4754836.9582331106 517984.86328312766,4754859.4006222263 517999.20147617353,4754869.3750173887 518023.51406438177,4754878.726012853 518049.69685168291,4754883.0898107365 518072.76264049584,4754874.3622149695 518092.08803112287,4754865.0112195052</gml:coordinates> 
  </gml:LinearRing>
  </gml:outerBoundaryIs>
  </gml:Polygon>
  </ogr:geometryProperty>
  <ogr:Campo1 /> 
  <ogr:Campo2 /> 
  <ogr:Campo3 /> 
  <ogr:Campo4 /> 
  <ogr:Campo5 /> 
  <ogr:Campo6 /> 
  <ogr:Campo7 /> 
  </ogr:prueba>
  </gml:featureMember>
  </ogr:FeatureCollection>

GML from gvSIG

<cit:gestfore.shp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.opengis.net/gml" xmlns:cit="http://www.gvsig.org/cit" xsi:schemaLocation="http://www.gvsig.org/cit cit.xsd">
  <gml:name>gestfore.shp</gml:name> 
<gml:boundedBy>
<gml:Box gml:srsName="http://www.opengis.net/gml/srs/epsg.xml#23030">
<gml:coord>
 <gml:X>509296.3493197768</gml:X> 
  <gml:Y>4754836.958233111</gml:Y> 
  </gml:coord>
<gml:coord>
  <gml:X>518092.08803112287</gml:X> 
  <gml:Y>4763261.318750359</gml:Y> 
  </gml:coord>
  </gml:Box>
  </gml:boundedBy>
<gml:featureMember>
<cit:Feature gml:fid="2">
<gml:Surface gml:srsName="http://www.opengis.net/gml/srs/epsg.xml#23030">
<gml:exterior>
<gml:LinearRing>
  <gml:coordinates>510612.9302840919,4758505.035971242 510719.9951351402,4758592.026162719 510914.05017766514,4758672.324801005 511181.71230528585,4758779.389652054 511282.08560314355,4758632.175481862 511215.1700712384,4758458.195098909 511027.80658190395,4758190.532971288 510980.96570957033,4758183.841418098 510766.8360074738,4758357.821801051 510766.8360074738,4758357.821801051</gml:coordinates> 
  </gml:LinearRing>
  </gml:exterior>
  </gml:Surface>
  <Campo1 /> 
  <Campo2 /> 
  <Campo3 /> 
  <Campo4 /> 
  <Campo5 /> 
  <Campo6 /> 
  <Campo7 /> 
  </cit:Feature>
  </gml:featureMember>
  </cit:gestfore.shp>
 
Un saludo,
 
··················································································

David Alda Fernández de Lezea
Lurralde eta Biodibertsitate Saila / Dpto. de Territorio y Biodiversidad
 
IKT
Granja Modelo s/n · 01192 · Arkaute (Araba)

··················································································
Tlfnos.: 945-00-32-95                         Fax: 945-00.32.90
··················································································
email: dalda at ikt.es                                web: www.ikt.es
··················································································


More information about the Users mailing list