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
405be881
Commit
405be881
authored
May 29, 2015
by
duminil
Browse files
RegionChooser : Choosing where to extract zip file from novaFACTORY.
parent
5fc7827a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/eu/simstadt/regionchooser/RegionChooserFX.java
View file @
405be881
...
...
@@ -3,15 +3,20 @@
import
java.io.BufferedReader
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.Charset
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.Enumeration
;
import
java.util.logging.Logger
;
import
java.util.prefs.Preferences
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
javafx.application.Application
;
import
javafx.beans.value.ObservableValue
;
import
javafx.concurrent.Task
;
...
...
@@ -89,16 +94,36 @@ protected Integer call() throws Exception {
new
Thread
(
task
).
start
();
}
public
void
doSomethingWithThisZIP
(
String
zipFilename
)
{
System
.
out
.
println
(
"Extract zipFile "
+
zipFilename
+
" to "
+
"unkownlocation"
);
public
void
doSomethingWithThisZIP
(
String
zipFilename
)
throws
IOException
{
ZipFile
zipFile
=
new
ZipFile
(
zipFilename
);
Enumeration
<?
extends
ZipEntry
>
entries
=
zipFile
.
entries
();
while
(
entries
.
hasMoreElements
())
{
ZipEntry
ze
=
entries
.
nextElement
();
if
(
ze
.
getName
().
toLowerCase
().
contains
(
"gml"
))
{
File
extractedCityGML
=
selectSaveFileWithDialog
(
null
,
ze
.
getName
(),
""
);
if
(
extractedCityGML
!=
null
)
{
InputStream
cityGMLInputStream
=
zipFile
.
getInputStream
(
ze
);
System
.
out
.
println
(
"Extract zipFile "
+
zipFilename
+
" to "
+
extractedCityGML
);
FileOutputStream
fos
=
new
FileOutputStream
(
extractedCityGML
);
byte
[]
bytes
=
new
byte
[
1024
];
int
length
;
while
((
length
=
cityGMLInputStream
.
read
(
bytes
))
>=
0
)
{
fos
.
write
(
bytes
,
0
,
length
);
}
cityGMLInputStream
.
close
();
fos
.
close
();
System
.
out
.
println
(
"Extracted"
);
}
}
}
zipFile
.
close
();
}
public
void
downloadRegionFromCityGML
(
String
wktPolygon
,
String
project
,
String
citygml
)
throws
IOException
,
ParseException
{
StringBuffer
sb
=
selectRegionDirectlyFromCityGML
(
citygmlPath
(
project
,
citygml
),
wktPolygon
);
File
buildingIdsFile
=
selectSaveFileWithDialog
(
project
,
citygml
);
File
buildingIdsFile
=
selectSaveFileWithDialog
(
project
,
citygml
,
"selected_region"
);
if
(
buildingIdsFile
!=
null
)
{
BufferedWriter
writer
=
Files
.
newBufferedWriter
(
buildingIdsFile
.
toPath
());
writer
.
write
(
sb
.
toString
());
...
...
@@ -149,12 +174,20 @@ public StringBuffer selectRegionDirectlyFromCityGML(Path citygmlPath, String wkt
}
private
File
selectSaveFileWithDialog
(
String
project
,
String
citygml
)
{
private
File
selectSaveFileWithDialog
(
String
project
,
String
citygml
,
String
suffix
)
{
Stage
mainStage
=
(
Stage
)
Browser
.
this
.
getScene
().
getWindow
();
FileChooser
fileChooser
=
new
FileChooser
();
fileChooser
.
setTitle
(
"Save CITYGML ids"
);
fileChooser
.
setInitialDirectory
(
repo
.
resolve
(
project
+
".simstadt"
).
toFile
());
fileChooser
.
setInitialFileName
(
citygml
.
replace
(
"."
,
"_selected_region."
));
if
(
project
!=
null
)
{
fileChooser
.
setInitialDirectory
(
repo
.
resolve
(
project
+
".simstadt"
).
toFile
());
}
else
{
fileChooser
.
setInitialDirectory
(
repo
.
toFile
());
}
if
(
suffix
.
isEmpty
())
{
fileChooser
.
setInitialFileName
(
citygml
);
}
else
{
fileChooser
.
setInitialFileName
(
citygml
.
replace
(
"."
,
"_"
+
suffix
+
"."
));
}
FileChooser
.
ExtensionFilter
extFilter
=
new
FileChooser
.
ExtensionFilter
(
"GML files (*.gml)"
,
"*.gml"
);
fileChooser
.
getExtensionFilters
().
add
(
extFilter
);
return
fileChooser
.
showSaveDialog
(
mainStage
);
...
...
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