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
4e46e9df
Commit
4e46e9df
authored
May 13, 2016
by
duminil
Browse files
RegionChooser: Separate class for Region Extractor
parent
ddf15a0f
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/eu/simstadt/regionchooser/RegionChooserFX.java
View file @
4e46e9df
...
@@ -6,21 +6,15 @@
...
@@ -6,21 +6,15 @@
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.nio.charset.Charset
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.util.Enumeration
;
import
java.util.Enumeration
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
java.util.prefs.Preferences
;
import
java.util.prefs.Preferences
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
java.util.zip.ZipFile
;
import
com.vividsolutions.jts.geom.Coordinate
;
import
com.vividsolutions.jts.geom.Geometry
;
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.ParseException
;
import
com.vividsolutions.jts.io.WKTReader
;
import
com.vividsolutions.jts.io.WKTReader
;
import
eu.simstadt.nf4j.ExportJobFromJavaFXRegionChooser
;
import
eu.simstadt.nf4j.ExportJobFromJavaFXRegionChooser
;
...
@@ -121,7 +115,7 @@ public void extractZIPtoGML(String zipFilename) throws IOException {
...
@@ -121,7 +115,7 @@ public void extractZIPtoGML(String zipFilename) throws IOException {
public
void
downloadRegionFromCityGML
(
String
wktPolygon
,
String
project
,
String
citygml
)
throws
IOException
,
public
void
downloadRegionFromCityGML
(
String
wktPolygon
,
String
project
,
String
citygml
)
throws
IOException
,
ParseException
{
ParseException
{
StringBuffer
sb
=
selectRegionDirectlyFromCityGML
(
citygmlPath
(
project
,
citygml
),
wktPolygon
);
StringBuffer
sb
=
RegionExtractor
.
selectRegionDirectlyFromCityGML
(
citygmlPath
(
project
,
citygml
),
wktPolygon
);
File
buildingIdsFile
=
selectSaveFileWithDialog
(
project
,
citygml
,
"selected_region"
);
File
buildingIdsFile
=
selectSaveFileWithDialog
(
project
,
citygml
,
"selected_region"
);
if
(
buildingIdsFile
!=
null
)
{
if
(
buildingIdsFile
!=
null
)
{
...
@@ -131,49 +125,6 @@ public void downloadRegionFromCityGML(String wktPolygon, String project, String
...
@@ -131,49 +125,6 @@ public void downloadRegionFromCityGML(String wktPolygon, String project, String
}
}
}
}
public
StringBuffer
selectRegionDirectlyFromCityGML
(
Path
citygmlPath
,
String
wktPolygon
)
throws
IOException
,
ParseException
{
//TODO: Write directly to file
// Instant start = Instant.now();
Geometry
poly
=
wktReader
.
read
(
wktPolygon
);
final
GeometryFactory
gf
=
new
GeometryFactory
();
String
s
=
new
String
(
Files
.
readAllBytes
(
citygmlPath
),
Charset
.
defaultCharset
());
Pattern
cityObjectPattern
=
Pattern
.
compile
(
"(?s)<(core:)?cityObjectMember>.*?<\\/(core:)?cityObjectMember>\\s*"
);
Pattern
gsk3CoordinatesPattern
=
Pattern
.
compile
(
"(?<![\\d\\.])(3\\d\\d\\d\\d\\d\\d[\\.\\d]*) (5\\d\\d\\d\\d\\d\\d[\\.\\d]*)"
);
Matcher
cityObjectMatcher
=
cityObjectPattern
.
matcher
(
s
);
StringBuffer
sb
=
new
StringBuffer
();
int
i
=
0
;
while
(
cityObjectMatcher
.
find
())
{
cityObjectMatcher
.
appendReplacement
(
sb
,
""
);
String
cityObject
=
cityObjectMatcher
.
group
();
Matcher
gsk3CoordinatesMatcher
=
gsk3CoordinatesPattern
.
matcher
(
cityObject
);
int
coordinatesCount
=
0
;
double
xTotal
=
0
;
double
yTotal
=
0
;
while
(
gsk3CoordinatesMatcher
.
find
())
{
coordinatesCount
++;
xTotal
+=
Double
.
valueOf
(
gsk3CoordinatesMatcher
.
group
(
1
));
yTotal
+=
Double
.
valueOf
(
gsk3CoordinatesMatcher
.
group
(
2
));
}
double
x
=
xTotal
/
coordinatesCount
;
double
y
=
yTotal
/
coordinatesCount
;
Coordinate
coord
=
new
Coordinate
(
x
,
y
);
Point
point
=
gf
.
createPoint
(
coord
);
if
(
point
.
within
(
poly
))
{
i
++;
sb
.
append
(
cityObject
);
}
}
System
.
out
.
println
(
"Buildings found in selected region "
+
i
);
cityObjectMatcher
.
appendTail
(
sb
);
// System.out.println(Duration.between(start, Instant.now()));
return
sb
;
}
private
File
selectSaveFileWithDialog
(
String
project
,
String
citygml
,
String
suffix
)
{
private
File
selectSaveFileWithDialog
(
String
project
,
String
citygml
,
String
suffix
)
{
Stage
mainStage
=
(
Stage
)
Browser
.
this
.
getScene
().
getWindow
();
Stage
mainStage
=
(
Stage
)
Browser
.
this
.
getScene
().
getWindow
();
FileChooser
fileChooser
=
new
FileChooser
();
FileChooser
fileChooser
=
new
FileChooser
();
...
...
src/eu/simstadt/regionchooser/RegionExtractor.java
0 → 100644
View file @
4e46e9df
package
eu.simstadt.regionchooser
;
import
java.io.IOException
;
import
java.nio.charset.Charset
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
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
;
public
class
RegionExtractor
{
static
private
WKTReader
wktReader
=
new
WKTReader
();
static
public
StringBuffer
selectRegionDirectlyFromCityGML
(
Path
citygmlPath
,
String
wktPolygon
)
throws
IOException
,
ParseException
{
//TODO: Write directly to file
// Instant start = Instant.now();
Geometry
poly
=
wktReader
.
read
(
wktPolygon
);
final
GeometryFactory
gf
=
new
GeometryFactory
();
String
s
=
new
String
(
Files
.
readAllBytes
(
citygmlPath
),
Charset
.
defaultCharset
());
Pattern
cityObjectPattern
=
Pattern
.
compile
(
"(?s)<(core:)?cityObjectMember>.*?<\\/(core:)?cityObjectMember>\\s*"
);
Pattern
gsk3CoordinatesPattern
=
Pattern
.
compile
(
"(?<![\\d\\.])(3\\d\\d\\d\\d\\d\\d[\\.\\d]*) (5\\d\\d\\d\\d\\d\\d[\\.\\d]*)"
);
Matcher
cityObjectMatcher
=
cityObjectPattern
.
matcher
(
s
);
StringBuffer
sb
=
new
StringBuffer
();
int
i
=
0
;
while
(
cityObjectMatcher
.
find
())
{
cityObjectMatcher
.
appendReplacement
(
sb
,
""
);
String
cityObject
=
cityObjectMatcher
.
group
();
Matcher
gsk3CoordinatesMatcher
=
gsk3CoordinatesPattern
.
matcher
(
cityObject
);
int
coordinatesCount
=
0
;
double
xTotal
=
0
;
double
yTotal
=
0
;
while
(
gsk3CoordinatesMatcher
.
find
())
{
coordinatesCount
++;
xTotal
+=
Double
.
valueOf
(
gsk3CoordinatesMatcher
.
group
(
1
));
yTotal
+=
Double
.
valueOf
(
gsk3CoordinatesMatcher
.
group
(
2
));
}
double
x
=
xTotal
/
coordinatesCount
;
double
y
=
yTotal
/
coordinatesCount
;
Coordinate
coord
=
new
Coordinate
(
x
,
y
);
Point
point
=
gf
.
createPoint
(
coord
);
if
(
point
.
within
(
poly
))
{
i
++;
sb
.
append
(
cityObject
);
}
}
System
.
out
.
println
(
"Buildings found in selected region "
+
i
);
cityObjectMatcher
.
appendTail
(
sb
);
// System.out.println(Duration.between(start, Instant.now()));
return
sb
;
}
}
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