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
b6fe0254
Commit
b6fe0254
authored
2 years ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
Added SRS Name patterns.
parent
c611eca9
master
develop
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/eu/simstadt/regionchooser/RegionChooserUtils.java
+16
-15
...in/java/eu/simstadt/regionchooser/RegionChooserUtils.java
src/test/java/eu/simstadt/regionchooser/CRSfromCityGMLHeaderTests.java
+8
-8
.../eu/simstadt/regionchooser/CRSfromCityGMLHeaderTests.java
with
24 additions
and
23 deletions
+24
-23
src/main/java/eu/simstadt/regionchooser/RegionChooserUtils.java
+
16
-
15
View file @
b6fe0254
...
...
@@ -22,6 +22,7 @@
public
static
final
CoordinateReferenceSystem
WGS84
=
CRS_FACTORY
.
createFromName
(
"EPSG:4326"
);
private
static
final
Pattern
srsNamePattern
=
Pattern
.
compile
(
"(?i)(?<=srsName=[\"'])[^\"']+(?=[\"'])"
);
private
static
final
int
CITYGML_HEADER_LENGTH
=
50
;
private
static
final
String
EPSG
=
"EPSG:"
;
private
RegionChooserUtils
()
{
// only static use
...
...
@@ -56,27 +57,27 @@ private static CoordinateReferenceSystem crsFromSrsName(String srsName) {
Pattern
pOGC
=
Pattern
.
compile
(
"urn:ogc:def:crs(?:,crs)?:EPSG:[\\d\\.]*:([\\d]+)\\D*"
);
Matcher
mOGC
=
pOGC
.
matcher
(
srsName
);
if
(
mOGC
.
find
())
{
return
CRS_FACTORY
.
createFromName
(
"
EPSG
:"
+
mOGC
.
group
(
1
));
return
CRS_FACTORY
.
createFromName
(
EPSG
+
mOGC
.
group
(
1
));
}
// urn:adv:crs:DE_DHDN_3GK3*DE_DHHN92_NH
// urn:adv:crs:ETRS89_UTM32*DE_DHHN92_NH
Pattern
pURN
=
Pattern
.
compile
(
"urn:adv:crs:([^\\*]+)"
);
Matcher
mURN
=
pURN
.
matcher
(
srsName
);
//NOTE: Could use a HashMap if the switch/case becomes too long.
if
(
mURN
.
find
())
{
switch
(
mURN
.
group
(
1
))
{
case
"DE_DHDN_3GK2"
:
return
CRS_FACTORY
.
createFromName
(
"EPSG:31466"
);
case
"DE_DHDN_3GK3"
:
return
CRS_FACTORY
.
createFromName
(
"EPSG:31467"
);
case
"DE_DHDN_3GK4"
:
return
CRS_FACTORY
.
createFromName
(
"EPSG:31468"
);
case
"DE_DHDN_3GK5"
:
return
CRS_FACTORY
.
createFromName
(
"EPSG:31469"
);
case
"ETRS89_UTM32"
:
return
CRS_FACTORY
.
createFromName
(
"EPSG:25832"
);
default
:
// nothing found
String
shortSrsName
=
mURN
.
group
(
1
);
// Gauss Krueger:
if
(
shortSrsName
.
startsWith
(
"DE_DHDN_3GK"
))
{
int
gaussKruegerBaseEPSG
=
31464
;
int
gaussKruegerId
=
Integer
.
parseInt
(
shortSrsName
.
substring
(
11
));
return
CRS_FACTORY
.
createFromName
(
EPSG
+
(
gaussKruegerBaseEPSG
+
gaussKruegerId
));
}
// UTM North:
if
(
shortSrsName
.
startsWith
(
"ETRS89_UTM"
))
{
int
utmBaseEPSG
=
25800
;
int
utmId
=
Integer
.
parseInt
(
shortSrsName
.
substring
(
10
));
return
CRS_FACTORY
.
createFromName
(
EPSG
+
(
utmBaseEPSG
+
utmId
));
}
}
throw
new
IllegalArgumentException
(
"Unknown srsName format: "
+
srsName
);
...
...
This diff is collapsed.
Click to expand it.
src/test/java/eu/simstadt/regionchooser/CRSfromCityGMLHeaderTests.java
+
8
-
8
View file @
b6fe0254
...
...
@@ -8,7 +8,7 @@
import
org.junit.jupiter.api.Test
;
public
class
CRSfromCityGMLHeaderTests
class
CRSfromCityGMLHeaderTests
{
private
Path
repo
=
Paths
.
get
(
"src/test/resources/testdata"
);
...
...
@@ -17,39 +17,39 @@ private void testExtractCSRNameFromHeader(Path citygmlPath, String crsName) thro
}
@Test
public
void
testExtractCRSFromStuttgart
()
throws
IOException
{
void
testExtractCRSFromStuttgart
()
throws
IOException
{
testExtractCSRNameFromHeader
(
repo
.
resolve
(
"Stuttgart.proj/Stuttgart_LOD0_LOD1_buildings_and_trees.gml"
),
"EPSG:31463"
);
}
@Test
public
void
testExtractCRSFromGruenbuehl
()
throws
IOException
{
void
testExtractCRSFromGruenbuehl
()
throws
IOException
{
testExtractCSRNameFromHeader
(
repo
.
resolve
(
"Gruenbuehl.proj/20140218_Gruenbuehl_LOD2_1building.gml"
),
"EPSG:31467"
);
}
@Test
public
void
testExtractCRSFromMunich
()
throws
IOException
{
void
testExtractCRSFromMunich
()
throws
IOException
{
testExtractCSRNameFromHeader
(
repo
.
resolve
(
"Muenchen.proj/Munich_v_1_0_0.gml"
),
"EPSG:32632"
);
}
@Test
public
void
testExtractCRSFromNYC
()
throws
IOException
{
void
testExtractCRSFromNYC
()
throws
IOException
{
testExtractCSRNameFromHeader
(
repo
.
resolve
(
"NewYork.proj/ManhattanSmall.gml"
),
"EPSG:32118"
);
}
@Test
public
void
testExtractCRSFromAachen
()
throws
IOException
{
void
testExtractCRSFromAachen
()
throws
IOException
{
testExtractCSRNameFromHeader
(
repo
.
resolve
(
"Others.proj/Aachen_LoD2_293_5623_1_NW.gml"
),
"EPSG:25832"
);
}
@Test
public
void
testExtractCRSFromValladolid
()
throws
IOException
{
void
testExtractCRSFromValladolid
()
throws
IOException
{
testExtractCSRNameFromHeader
(
repo
.
resolve
(
"Others.proj/Valladolid_Spain_only_header.gml"
),
"EPSG:25830"
);
}
@Test
public
void
testDontExtractCRSFromBrokenCityGML
()
throws
IOException
{
void
testDontExtractCRSFromBrokenCityGML
()
throws
IOException
{
Path
citygmlPath
=
repo
.
resolve
(
"Others.proj/SimpleSolid_MSBS.gml"
);
assertThrows
(
IllegalArgumentException
.
class
,
()
->
{
testExtractCSRNameFromHeader
(
citygmlPath
,
"Nothing found. Should throw an exception"
);
...
...
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