Skip to content

Commit

Permalink
[GEOT-5448] GML3 parser reads poslist in 3d crs as a 2d one
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Jun 23, 2016
1 parent 891345c commit 8d722c9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Expand Up @@ -95,7 +95,9 @@ static CoordinateReferenceSystem crs(Node node) {
/**
* Returns the number of dimensions for the specified node, eventually recursing up to find the
* parent node that has the indication of the dimensions (normally the top-most geometry element
* has it, not the posList). Returns 2 if no srsDimension attribute could be found.
* has it, not the posList). If no srsDimension can be found, check the srsName the same way
* and return the srsDimensions instead.
* Returns 2 if no srsDimension or srsName attribute could be found.
*
* @param node
* @return
Expand All @@ -109,6 +111,14 @@ public static int dimensions(Node node) {
}
current = current.getParent();
}
current = node;
while (current != null) {
CoordinateReferenceSystem crs = crs(current);
if (crs != null) {
return crs.getCoordinateSystem().getDimension();
}
current = current.getParent();
}

return 2;
}
Expand Down
@@ -1,5 +1,8 @@
package org.geotools.gml3;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
Expand All @@ -13,10 +16,19 @@

import junit.framework.TestCase;

import org.geotools.geometry.jts.CompoundCurvedGeometry;
import org.geotools.geometry.jts.coordinatesequence.CoordinateSequences;
import org.geotools.gml3.v3_2.GMLParsingTest;
import org.geotools.xml.Parser;
import org.geotools.xml.StreamingParser;
import org.opengis.feature.simple.SimpleFeature;
import org.w3c.dom.Document;

import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.io.WKTReader;

/**
*
*
Expand Down Expand Up @@ -76,4 +88,16 @@ public void testWithSchema() throws Exception {

assertEquals( 49, nfeatures );
}

public void testParse3D() throws Exception {
Parser p = new Parser(new GMLConfiguration());
Object g = p.parse(GML3ParsingTest.class.getResourceAsStream("polygon3d.xml"));
assertThat(g, instanceOf(Polygon.class));

Polygon polygon = (Polygon) g;
assertEquals(3, CoordinateSequences.coordinateDimension(polygon));
Geometry expected = new WKTReader().read(
"POLYGON((94000 471000 10, 94001 471000 11, 94001 471001 12, 94000 471001 13, 94000 471000 10))");
assertTrue(CoordinateSequences.equalsND(expected, polygon));
}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Polygon srsName="EPSG:7415">
<exterior>
<LinearRing>
<posList>94000 471000 10 94001 471000 11 94001 471001 12 94000 471001 13 94000 471000 10</posList>
</LinearRing>
</exterior>
</Polygon>

0 comments on commit 8d722c9

Please sign in to comment.