[geotk] Read Polygon from Xml Iso Metadata

Martin Desruisseaux martin.desruisseaux at geomatys.fr
Fri May 3 02:45:16 PDT 2013


Hello Robin

Sorry for the delayed reply. Do you have the geotk-xml-gml module in 
your classpath? With that module, the following code effectively prints 
"Number of geometry objects:  1"...

String xml =
         "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
         "<gmd:EX_Extent xmlns:gmd=\"http://www.isotc211.org/2005/gmd\" xmlns:gml=\"http://www.opengis.net/gml\">" +
         "    <gmd:geographicElement>" +
         "        <gmd:EX_BoundingPolygon>" +
         "            <gmd:polygon>" +
         "                <gml:Polygon srsName=\"urn:ogc:def:crs:epsg:7.9:4326\">" +
         "                    <gml:exterior>" +
         "                        <gml:LinearRing srsName=\"urn:ogc:def:crs:epsg:7.9:4326\">" +
         "                            <gml:posList>1.0 1.0 5.0 1.0 5.0 5.0 1.0 5.0 1.0 1.0</gml:posList>" +
         "                        </gml:LinearRing>" +
         "                    </gml:exterior>" +
         "                </gml:Polygon>" +
         "           </gmd:polygon>" +
         "       </gmd:EX_BoundingPolygon>" +
         "   </gmd:geographicElement>" +
         "</gmd:EX_Extent>";

Extent obj = (Extent) CSWMarshallerPool.getInstance().acquireUnmarshaller().unmarshal(new StringReader(xml));
for (GeographicExtent geographicExtent : obj.getGeographicElements()) {
     if (geographicExtent instanceof DefaultBoundingPolygon){
         DefaultBoundingPolygon defaultBoundingPolygon = (DefaultBoundingPolygon)geographicExtent;
         Collection polygons = defaultBoundingPolygon.getPolygons();
         System.out.println("Number of geometry objects:  " + polygons.size());
     }
}


(note: Thanks to Guilhem Legal for the code snippet).

     Martin




Le 26/04/13 11:03, robin berenger a écrit :
> Hello,
>
> I have a problem reading an xml file and filling a default metadata 
> with it. I can fill almost all attributes, but not
> Metadata -> Identification -> Extent ->GeographicElement -> 
> DefaultBoundingPolygon.
>
> When i write :
>
> for (GeographicExtent geographicExtent : geographicElements) {
>                         if (geographicExtent instanceof 
> DefaultBoundingPolygon){
>                             DefaultBoundingPolygon 
> defaultBoundingPolygon = (DefaultBoundingPolygon)geographicExtent;
>                             Collection<Geometry> polygons = 
> defaultBoundingPolygon.getPolygons();
>                             System.out.println("Number of geometry 
> objects :  :  " + polygons.size());
>                         }
>
> I get : Number of geometry objects   :  0
>
> Is it possible to read this Polygon? I have no problem readind a 
> bounding box .



More information about the Geotoolkit mailing list