Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
RegionChooser
Commits
809a82ae
Commit
809a82ae
authored
May 05, 2017
by
duminil
Browse files
RegionChooser: Test with xmin, xmax, ymin and ymax for buildings.
parent
68891bca
Changes
4
Show whitespace changes
Inline
Side-by-side
src/eu/simstadt/regionchooser/RegionExtractor.java
View file @
809a82ae
...
...
@@ -5,7 +5,9 @@
import
java.util.logging.Logger
;
import
javax.xml.stream.XMLStreamException
;
import
org.xml.sax.SAXParseException
;
import
com.vividsolutions.jts.geom.Coordinate
;
import
com.vividsolutions.jts.geom.Geometry
;
import
com.vividsolutions.jts.geom.GeometryFactory
;
import
com.vividsolutions.jts.geom.Point
;
import
com.vividsolutions.jts.io.ParseException
;
import
com.vividsolutions.jts.io.WKTReader
;
...
...
@@ -21,6 +23,7 @@
static
private
WKTReader
wktReader
=
new
WKTReader
();
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
RegionExtractor
.
class
.
getName
());
private
static
final
GeometryFactory
gf
=
new
GeometryFactory
();
static
public
StringBuffer
selectRegionDirectlyFromCityGML
(
Path
citygmlPath
,
String
wktPolygon
,
String
srsName
)
throws
SAXParseException
,
XMLStreamException
,
ParseException
,
XPathParseException
,
NavException
,
...
...
@@ -37,7 +40,8 @@ static public StringBuffer selectRegionDirectlyFromCityGML(Path citygmlPath, Str
sb
.
append
(
citygml
.
getHeader
());
}
buildingsCount
+=
1
;
Point
point
=
buildingXmlNode
.
getCenterOfMass
();
Coordinate
coord
=
new
Coordinate
(
buildingXmlNode
.
x
,
buildingXmlNode
.
y
);
Point
point
=
gf
.
createPoint
(
coord
);
//NOTE: Should it be in buildingXmlNode?
if
(
point
.
within
(
poly
))
{
foundBuildingsCount
++;
sb
.
append
(
buildingXmlNode
.
toString
());
...
...
src/eu/simstadt/regionchooser/citygml_parser/BuildingXmlNode.java
View file @
809a82ae
package
eu.simstadt.regionchooser.citygml_parser
;
import
com.vividsolutions.jts.geom.Coordinate
;
import
com.vividsolutions.jts.geom.GeometryFactory
;
import
com.vividsolutions.jts.geom.Point
;
import
com.ximpleware.AutoPilot
;
import
com.ximpleware.NavException
;
import
com.ximpleware.VTDNav
;
...
...
@@ -17,19 +14,32 @@
private
int
buildingLength
;
private
VTDNav
navigator
;
private
AutoPilot
coordinatesFinder
;
private
static
final
GeometryFactory
gf
=
new
GeometryFactory
();
public
Double
x
;
public
Double
xMin
;
public
Double
xMax
;
public
Double
yMin
;
public
Double
yMax
;
public
Double
y
;
public
BuildingXmlNode
(
VTDNav
navigator
,
int
buildingOffset
,
int
buildingLength
)
{
public
BuildingXmlNode
(
VTDNav
navigator
,
int
buildingOffset
,
int
buildingLength
)
throws
NumberFormatException
,
XPathParseException
,
XPathEvalException
,
NavException
{
this
.
navigator
=
navigator
;
this
.
coordinatesFinder
=
new
AutoPilot
(
navigator
);
this
.
buildingLength
=
buildingLength
;
this
.
buildingOffset
=
buildingOffset
;
extractCoordinates
();
//NOTE: Should it be done lazily? Is there any reason to extract a BuildingXmlNode without coordinates?
}
public
Point
getCenterOfMass
()
throws
XPathParseException
,
NumberFormatException
,
XPathEvalException
,
NavException
{
private
void
extractCoordinates
()
throws
XPathParseException
,
NumberFormatException
,
XPathEvalException
,
NavException
{
int
coordinatesCount
=
0
;
double
xTotal
=
0
;
double
yTotal
=
0
;
double
x
,
y
;
double
xMin
=
Double
.
MAX_VALUE
;
double
xMax
=
Double
.
MIN_VALUE
;
double
yMin
=
Double
.
MAX_VALUE
;
double
yMax
=
Double
.
MIN_VALUE
;
coordinatesFinder
.
selectXPath
(
".//posList|.//pos"
);
while
(
coordinatesFinder
.
evalXPath
()
!=
-
1
)
{
...
...
@@ -40,15 +50,30 @@ public Point getCenterOfMass() throws XPathParseException, NumberFormatException
String
[]
coordinates
=
posList
.
trim
().
split
(
"\\s+"
);
for
(
int
k
=
0
;
k
<
coordinates
.
length
;
k
=
k
+
3
)
{
coordinatesCount
++;
xTotal
+=
Double
.
valueOf
(
coordinates
[
k
]);
yTotal
+=
Double
.
valueOf
(
coordinates
[
k
+
1
]);
x
=
Double
.
valueOf
(
coordinates
[
k
]);
y
=
Double
.
valueOf
(
coordinates
[
k
+
1
]);
if
(
x
<
xMin
)
{
xMin
=
x
;
}
if
(
y
<
yMin
)
{
yMin
=
y
;
}
double
x
=
xTotal
/
coordinatesCount
;
double
y
=
yTotal
/
coordinatesCount
;
Coordinate
coord
=
new
Coordinate
(
x
,
y
);
return
gf
.
createPoint
(
coord
);
if
(
x
>
xMax
)
{
xMax
=
x
;
}
if
(
y
>
yMax
)
{
yMax
=
y
;
}
xTotal
+=
x
;
yTotal
+=
y
;
}
}
this
.
xMin
=
xMin
;
this
.
xMax
=
xMax
;
this
.
yMin
=
yMin
;
this
.
yMax
=
yMax
;
this
.
x
=
xTotal
/
coordinatesCount
;
this
.
y
=
yTotal
/
coordinatesCount
;
}
public
String
toString
()
{
...
...
@@ -58,5 +83,4 @@ public String toString() {
return
null
;
}
}
}
src/eu/simstadt/regionchooser/citygml_parser/CityGmlIterator.java
View file @
809a82ae
...
...
@@ -63,7 +63,7 @@ public BuildingXmlNode next() {
buildingOffset
=
(
int
)
offsetAndLength
;
buildingLength
=
(
int
)
(
offsetAndLength
>>
32
);
return
new
BuildingXmlNode
(
navigator
,
buildingOffset
,
buildingLength
);
}
catch
(
NavException
ex
)
{
}
catch
(
NavException
|
NumberFormatException
|
XPathParseException
|
XPathEvalException
ex
)
{
LOGGER
.
warning
(
"Error while parsing "
+
citygmlPath
);
}
return
null
;
...
...
test/eu/simstadt/regionchooser/test/CitygmlParserTests.java
View file @
809a82ae
package
eu.simstadt.regionchooser.test
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.io.IOException
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
...
...
@@ -18,10 +19,16 @@ private void testNoNanInCoordinates(Path citygmlPath)
throws
NumberFormatException
,
XPathParseException
,
NavException
,
XPathEvalException
,
IOException
{
CityGmlIterator
buildingXmlNodes
=
new
CityGmlIterator
(
citygmlPath
);
for
(
BuildingXmlNode
buildingXmlNode
:
buildingXmlNodes
)
{
double
x
=
buildingXmlNode
.
getCenterOfMass
().
getX
();
double
y
=
buildingXmlNode
.
getCenterOfMass
().
getY
();
assertFalse
(
"Coordinate should be a double"
,
Double
.
isNaN
(
x
));
assertFalse
(
"Coordinate should be a double"
,
Double
.
isNaN
(
y
));
assertFalse
(
"Coordinate should be a double"
,
Double
.
isNaN
(
buildingXmlNode
.
x
));
assertFalse
(
"Coordinate should be a double"
,
Double
.
isNaN
(
buildingXmlNode
.
y
));
assertFalse
(
"Coordinate should be a double"
,
Double
.
isNaN
(
buildingXmlNode
.
xMax
));
assertFalse
(
"Coordinate should be a double"
,
Double
.
isNaN
(
buildingXmlNode
.
yMax
));
assertFalse
(
"Coordinate should be a double"
,
Double
.
isNaN
(
buildingXmlNode
.
xMin
));
assertFalse
(
"Coordinate should be a double"
,
Double
.
isNaN
(
buildingXmlNode
.
yMin
));
assertTrue
(
"Coordinates Min/Max should be plausible"
,
buildingXmlNode
.
xMax
>
buildingXmlNode
.
x
);
assertTrue
(
"Coordinates Min/Max should be plausible"
,
buildingXmlNode
.
yMax
>
buildingXmlNode
.
y
);
assertTrue
(
"Coordinates Min/Max should be plausible"
,
buildingXmlNode
.
xMin
<
buildingXmlNode
.
x
);
assertTrue
(
"Coordinates Min/Max should be plausible"
,
buildingXmlNode
.
yMin
<
buildingXmlNode
.
y
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment