Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
RegionChooser
Commits
c104f778
Commit
c104f778
authored
10 years ago
by
duminil
Browse files
Options
Download
Email Patches
Plain Diff
selectRegionDirectlyFromCityGML
parent
b8437c3c
master
develop
migrate_to_Java11
0.2.2
0.1.0
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/eu/simstadt/regionchooser/RegionChooserFX.java
+70
-33
src/eu/simstadt/regionchooser/RegionChooserFX.java
website/script/simstadt_openlayers.js
+1
-2
website/script/simstadt_openlayers.js
with
71 additions
and
35 deletions
+71
-35
src/eu/simstadt/regionchooser/RegionChooserFX.java
+
70
-
33
View file @
c104f778
...
@@ -3,10 +3,15 @@
...
@@ -3,10 +3,15 @@
import
java.io.BufferedWriter
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
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.time.Duration
;
import
java.time.Instant
;
import
java.util.List
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
javafx.application.Application
;
import
javafx.application.Application
;
import
javafx.beans.value.ObservableValue
;
import
javafx.beans.value.ObservableValue
;
import
javafx.concurrent.Worker.State
;
import
javafx.concurrent.Worker.State
;
...
@@ -69,41 +74,60 @@ public void downloadRegion(String wktPolygon) {
...
@@ -69,41 +74,60 @@ public void downloadRegion(String wktPolygon) {
System
.
out
.
println
(
"FROM JAVA : DO SOMETHING with "
+
wktPolygon
);
System
.
out
.
println
(
"FROM JAVA : DO SOMETHING with "
+
wktPolygon
);
}
}
public
int
downloadRegionFromCityGML
(
String
wktPolygon
,
String
project
,
String
citygml
,
JSObject
featureOverlay
)
public
void
downloadRegionFromCityGML
(
String
wktPolygon
,
String
project
,
String
citygml
,
JSObject
featureOverlay
)
throws
SAXParseException
,
XMLStreamException
,
ParseException
,
IOException
{
throws
IOException
,
ParseException
//FIXME: Why is this so slow?
{
SimStadtModel
model
=
SimStadtProject
.
loadModelWithoutSchemaValidation
(
citygmlPath
(
project
,
citygml
).
toFile
());
StringBuffer
sb
=
selectRegionDirectlyFromCityGML
(
citygmlPath
(
project
,
citygml
),
wktPolygon
);
Geometry
poly
=
wktReader
.
read
(
wktPolygon
);
final
GeometryFactory
gf
=
new
GeometryFactory
();
File
buildingIdsFile
=
selectSaveFileWithDialog
(
project
,
citygml
);
File
buildingIdsFile
=
selectSaveFileWithDialog
(
project
,
citygml
);
if
(
buildingIdsFile
!=
null
)
{
if
(
buildingIdsFile
!=
null
)
{
BufferedWriter
writer
=
Files
.
newBufferedWriter
(
buildingIdsFile
.
toPath
());
BufferedWriter
writer
=
Files
.
newBufferedWriter
(
buildingIdsFile
.
toPath
());
writer
.
write
(
sb
.
toString
());
writer
.
close
();
}
}
//TODO: What's the easiest way to get WGS84 coordinates of building center?
public
StringBuffer
selectRegionDirectlyFromCityGML
(
Path
citygmlPath
,
String
wktPolygon
)
throws
IOException
,
for
(
Building
building
:
model
.
getCityDoctorBuildings
())
{
ParseException
{
BoundingShape
boundedBy
=
building
.
getCitygmlBuilding
().
getBoundedBy
();
//TODO: Write directly to file
if
(
boundedBy
!=
null
)
{
// Instant start = Instant.now();
Envelope
envelope
=
boundedBy
.
getEnvelope
();
Geometry
poly
=
wktReader
.
read
(
wktPolygon
);
if
(
envelope
!=
null
)
{
final
GeometryFactory
gf
=
new
GeometryFactory
();
List
<
Double
>
l
=
envelope
.
getLowerCorner
().
getValue
();
String
s
=
new
String
(
Files
.
readAllBytes
(
citygmlPath
),
Charset
.
defaultCharset
());
List
<
Double
>
h
=
envelope
.
getUpperCorner
().
getValue
();
double
x
=
(
l
.
get
(
0
)
+
h
.
get
(
0
))
*
0.5
;
Pattern
cityObjectPattern
=
Pattern
double
y
=
(
l
.
get
(
1
)
+
h
.
get
(
1
))
*
0.5
;
.
compile
(
"(?s)<(core:)?cityObjectMember>.*?<\\/(core:)?cityObjectMember>\\s*"
);
Coordinate
coord
=
new
Coordinate
(
x
,
y
);
Pattern
gsk3CoordinatesPattern
=
Pattern
Point
point
=
gf
.
createPoint
(
coord
);
.
compile
(
"(?<![\\d\\.])(3\\d\\d\\d\\d\\d\\d[\\.\\d]*) (5\\d\\d\\d\\d\\d\\d[\\.\\d]*)"
);
if
(
point
.
within
(
poly
))
{
Matcher
cityObjectMatcher
=
cityObjectPattern
.
matcher
(
s
);
//featureOverlay.call("addMarker", x, y, building.getGmlId());
StringBuffer
sb
=
new
StringBuffer
();
writer
.
write
(
building
.
getGmlId
()
+
"\r\n"
);
int
i
=
0
;
System
.
out
.
println
(
building
.
getGmlId
());
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
);
}
}
writer
.
close
();
}
}
System
.
out
.
println
(
"Buildings found in selected region "
+
i
);
cityObjectMatcher
.
appendTail
(
sb
);
// System.out.println(Duration.between(start, Instant.now()));
return
sb
;
return
model
.
getCityDoctorBuildings
().
size
();
}
}
private
File
selectSaveFileWithDialog
(
String
project
,
String
citygml
)
{
private
File
selectSaveFileWithDialog
(
String
project
,
String
citygml
)
{
...
@@ -111,14 +135,15 @@ private File selectSaveFileWithDialog(String project, String citygml) {
...
@@ -111,14 +135,15 @@ private File selectSaveFileWithDialog(String project, String citygml) {
FileChooser
fileChooser
=
new
FileChooser
();
FileChooser
fileChooser
=
new
FileChooser
();
fileChooser
.
setTitle
(
"Save CITYGML ids"
);
fileChooser
.
setTitle
(
"Save CITYGML ids"
);
fileChooser
.
setInitialDirectory
(
repo
.
resolve
(
project
+
".simstadt"
).
toFile
());
fileChooser
.
setInitialDirectory
(
repo
.
resolve
(
project
+
".simstadt"
).
toFile
());
fileChooser
.
setInitialFileName
(
citygml
.
split
(
"\\."
)[
0
]
+
"_selected_region
"
);
fileChooser
.
setInitialFileName
(
citygml
.
replace
(
"."
,
"_selected_region
."
)
);
FileChooser
.
ExtensionFilter
extFilter
=
new
FileChooser
.
ExtensionFilter
(
"
TXT
files (*.
txt
)"
,
"*.
txt
"
);
FileChooser
.
ExtensionFilter
extFilter
=
new
FileChooser
.
ExtensionFilter
(
"
GML
files (*.
gml
)"
,
"*.
gml
"
);
fileChooser
.
getExtensionFilters
().
add
(
extFilter
);
fileChooser
.
getExtensionFilters
().
add
(
extFilter
);
return
fileChooser
.
showSaveDialog
(
mainStage
);
return
fileChooser
.
showSaveDialog
(
mainStage
);
}
}
public
boolean
checkIfCityGMLSAreAvailable
(
String
project
,
String
citygml
)
{
public
boolean
checkIfCityGMLSAreAvailable
(
String
project
,
String
citygml
)
{
return
Files
.
isReadable
(
citygmlPath
(
project
,
citygml
));
Path
p
=
citygmlPath
(
project
,
citygml
);
return
Files
.
isReadable
(
p
);
}
}
public
void
log
(
String
text
)
public
void
log
(
String
text
)
...
@@ -145,13 +170,25 @@ public Browser() {
...
@@ -145,13 +170,25 @@ public Browser() {
(
ObservableValue
<?
extends
State
>
ov
,
State
oldState
,
State
newState
)
->
{
(
ObservableValue
<?
extends
State
>
ov
,
State
oldState
,
State
newState
)
->
{
if
(
newState
==
State
.
SUCCEEDED
)
{
if
(
newState
==
State
.
SUCCEEDED
)
{
JSObject
win
=
(
JSObject
)
webEngine
.
executeScript
(
"window"
);
JSObject
win
=
(
JSObject
)
webEngine
.
executeScript
(
"window"
);
win
.
setMember
(
"fxapp"
,
new
JavaScriptFXBridge
());
JavaScriptFXBridge
fxapp
=
new
JavaScriptFXBridge
();
win
.
setMember
(
"fxapp"
,
fxapp
);
webEngine
.
executeScript
(
"console.log = function(message)\n"
+
webEngine
.
executeScript
(
"console.log = function(message)\n"
+
"{\n"
+
"{\n"
+
" fxapp.log(message);\n"
+
" fxapp.log(message);\n"
+
"};"
);
"};"
);
}
// try {
});
// fxapp.selectRegionDirectlyFromCityGML(
// Paths.get("../TestRepository").resolve("Gruenbuehl.simstadt")
// .resolve("Gruenbuehl_LOD2_validated+ADE.gml"),
// "POLYGON((3515896.6132767177 5415942.563662692,3516013.1135652466 5415930.341095623,3516035.1608944996 5415925.696283888,3516052.531667652 5415905.3452489935,3516053.640043498 5415793.1428597355,3516092.996199113 5415790.117097386,3516086.9957373445 5415687.30812527,3515953.2106800284 5415687.710348818,3515893.4419519473 5415673.416324939,3515876.73573549 5415736.92758554,3515896.6132767177 5415942.563662692))"
// );
// } catch (Exception ex) {
// ex.printStackTrace();
//
// }
// System.exit(0);
}
});
//add the web view to the scene
//add the web view to the scene
getChildren
().
add
(
browser
);
getChildren
().
add
(
browser
);
}
}
...
...
This diff is collapsed.
Click to expand it.
website/script/simstadt_openlayers.js
+
1
-
2
View file @
c104f778
...
@@ -240,8 +240,7 @@ function downloadRegionFromCityGML(i) {
...
@@ -240,8 +240,7 @@ function downloadRegionFromCityGML(i) {
// Waiting 100ms in order to let the cursor change
// Waiting 100ms in order to let the cursor change
setTimeout
(
function
()
{
setTimeout
(
function
()
{
var
start
=
new
Date
().
getTime
();
var
start
=
new
Date
().
getTime
();
var
buildings_count
=
fxapp
.
downloadRegionFromCityGML
(
sketchAsWKT
(),
feature
.
get
(
"
project
"
),
feature
fxapp
.
downloadRegionFromCityGML
(
sketchAsWKT
(),
feature
.
get
(
"
project
"
),
feature
.
get
(
"
name
"
),
vectorSource
);
.
get
(
"
name
"
),
vectorSource
);
var
end
=
new
Date
().
getTime
();
var
end
=
new
Date
().
getTime
();
var
time
=
end
-
start
;
var
time
=
end
-
start
;
console
.
log
(
'
DL Execution time:
'
+
time
);
console
.
log
(
'
DL Execution time:
'
+
time
);
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Explore
Projects
Groups
Snippets