Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Geo Tools
Commits
0347b867
Commit
0347b867
authored
Jan 22, 2016
by
Matija Obreza
Browse files
First Longitude, then Latitude
parent
91299346
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys/geotools/CountryCLI.java
View file @
0347b867
...
...
@@ -24,9 +24,9 @@ public class CountryCLI {
Pattern
pattern
=
Pattern
.
compile
(
"^(\\w{3})[\\s,]+(\\-?\\d*\\.?\\d*)[\\s,]+(\\-?\\d*\\.?\\d*)$"
);
System
.
err
.
println
(
"Expects input rows in format: L
at
itude\tL
ong
itude"
);
System
.
err
.
println
(
"Expects input rows in format: L
ong
itude\tL
at
itude"
);
System
.
err
.
println
(
"Enter 'q' to quit."
);
System
.
out
.
println
(
"OrigCty\tL
at
itude\tL
ong
itude\tResult"
);
System
.
out
.
println
(
"OrigCty\tL
ong
itude\tL
at
itude\tResult"
);
String
input
=
null
;
do
{
input
=
br
.
readLine
();
...
...
@@ -37,10 +37,10 @@ public class CountryCLI {
Matcher
matcher
=
pattern
.
matcher
(
input
);
if
(
matcher
.
find
())
{
String
origCty
=
matcher
.
group
(
1
).
trim
();
float
l
at
itude
=
Float
.
parseFloat
(
matcher
.
group
(
2
).
replace
(
","
,
"."
));
float
l
ong
itude
=
Float
.
parseFloat
(
matcher
.
group
(
3
).
replace
(
","
,
"."
));
float
l
ong
itude
=
Float
.
parseFloat
(
matcher
.
group
(
2
).
replace
(
","
,
"."
));
float
l
at
itude
=
Float
.
parseFloat
(
matcher
.
group
(
3
).
replace
(
","
,
"."
));
System
.
out
.
println
(
l
at
itude
+
", "
+
l
ong
itude
+
", "
System
.
out
.
println
(
l
ong
itude
+
", "
+
l
at
itude
+
", "
+
countryOfOriginService
.
getCountries
(
longitude
,
latitude
,
origCty
,
ALLOWED_DISTANCE_MARGIN
));
}
else
{
...
...
@@ -53,9 +53,9 @@ public class CountryCLI {
}
private
static
void
doCSV
(
String
[]
arg
)
throws
IOException
{
int
columnOrigCty
=
5
;
int
columnLatitude
=
4
;
int
columnLongitude
=
3
;
int
columnLatitude
=
4
;
int
columnOrigCty
=
5
;
CSVWriter
writer
=
new
CSVWriter
(
new
OutputStreamWriter
(
System
.
out
),
','
,
'"'
,
'\\'
,
"\n"
);
CSVReader
reader
=
new
CSVReader
(
new
InputStreamReader
(
System
.
in
),
','
,
'"'
,
'\\'
,
0
,
false
);
...
...
src/main/java/org/genesys/geotools/LandOrSeaCLI.java
View file @
0347b867
...
...
@@ -26,9 +26,9 @@ public class LandOrSeaCLI {
Pattern
pattern
=
Pattern
.
compile
(
"^(\\-?\\d*\\.?\\d*)[ \\t,]+(\\-?\\d*\\.?\\d*)$"
);
System
.
err
.
println
(
"Expects input rows in format: L
at
itude\tL
ong
itude"
);
System
.
err
.
println
(
"Expects input rows in format: L
ong
itude\tL
at
itude"
);
System
.
err
.
println
(
"Enter 'q' to quit."
);
System
.
out
.
println
(
"L
at
itude\tL
ong
itude\tResult"
);
System
.
out
.
println
(
"L
ong
itude\tL
at
itude\tResult"
);
String
input
=
null
;
do
{
input
=
br
.
readLine
();
...
...
@@ -38,10 +38,10 @@ public class LandOrSeaCLI {
Matcher
matcher
=
pattern
.
matcher
(
input
);
if
(
matcher
.
find
())
{
float
l
at
itude
=
Float
.
parseFloat
(
matcher
.
group
(
1
).
replace
(
","
,
"."
));
float
l
ong
itude
=
Float
.
parseFloat
(
matcher
.
group
(
2
).
replace
(
","
,
"."
));
float
l
ong
itude
=
Float
.
parseFloat
(
matcher
.
group
(
1
).
replace
(
","
,
"."
));
float
l
at
itude
=
Float
.
parseFloat
(
matcher
.
group
(
2
).
replace
(
","
,
"."
));
System
.
out
.
println
(
l
at
itude
+
", "
+
l
ong
itude
+
", "
System
.
out
.
println
(
l
ong
itude
+
", "
+
l
at
itude
+
", "
+
landOrSeaService
.
classifyLocation
(
longitude
,
latitude
,
ALLOWED_DISTANCE_MARGIN
));
}
else
{
...
...
@@ -54,8 +54,8 @@ public class LandOrSeaCLI {
}
private
static
void
doCSV
(
String
[]
arg
)
throws
IOException
{
int
columnLatitude
=
4
;
int
columnLongitude
=
3
;
int
columnLatitude
=
4
;
CSVWriter
writer
=
new
CSVWriter
(
new
OutputStreamWriter
(
System
.
out
),
','
,
'"'
,
'\\'
,
"\n"
);
CSVReader
reader
=
new
CSVReader
(
new
InputStreamReader
(
System
.
in
),
','
,
'"'
,
'\\'
,
0
,
false
);
...
...
@@ -75,8 +75,8 @@ public class LandOrSeaCLI {
String
[]
writeLine
=
Arrays
.
copyOf
(
nextLine
,
nextLine
.
length
+
1
);
try
{
float
latitude
=
Float
.
parseFloat
(
nextLine
[
columnLatitude
].
trim
());
float
longitude
=
Float
.
parseFloat
(
nextLine
[
columnLongitude
].
trim
());
float
latitude
=
Float
.
parseFloat
(
nextLine
[
columnLatitude
].
trim
());
try
{
writeLine
[
writeLine
.
length
-
1
]
=
landOrSeaService
.
classifyLocation
(
longitude
,
latitude
,
...
...
src/main/java/org/genesys/geotools/LandOrSeaServiceImpl.java
View file @
0347b867
...
...
@@ -63,21 +63,20 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
.
build
(
new
CacheLoader
<
LonLatCacheKey
,
String
>()
{
public
String
load
(
LonLatCacheKey
key
)
throws
Exception
{
// System.err.println("Loading");
return
_classifyLocation
(
key
.
getLongitude
(),
key
.
getLatitude
(),
key
.
getAllowedDistanceMargin
());
return
_classifyLocation
(
key
.
getLongitude
(),
key
.
getLatitude
(),
key
.
getAllowedDistanceMargin
());
}
});
}
public
String
classifyLocation
(
float
longitude
,
float
latitude
,
int
allowedDistance
FromLand
)
throws
Exception
{
public
String
classifyLocation
(
float
longitude
,
float
latitude
,
int
allowedDistance
Margin
)
throws
Exception
{
try
{
return
classifierCache
.
get
(
new
LonLatCacheKey
(
longitude
,
latitude
,
allowedDistance
FromLand
));
return
classifierCache
.
get
(
new
LonLatCacheKey
(
longitude
,
latitude
,
allowedDistance
Margin
));
}
catch
(
ExecutionException
e
)
{
throw
new
Exception
(
e
.
getCause
());
}
}
private
String
_classifyLocation
(
float
longitude
,
float
latitude
,
int
allowedDistance
FromLand
)
throws
Exception
{
private
String
_classifyLocation
(
float
longitude
,
float
latitude
,
int
allowedDistance
Margin
)
throws
Exception
{
Point
point
=
geometryFactory
.
createPoint
(
new
Coordinate
(
longitude
,
latitude
));
...
...
@@ -88,7 +87,7 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
// Create a buffer and check for Land
Filter
filterBuffered
=
ff
.
intersects
(
ff
.
property
(
"the_geom"
),
ff
.
literal
(
ShapefileUtils
.
getPointBuffer
(
point
,
allowedDistance
FromLand
)));
ff
.
literal
(
ShapefileUtils
.
getPointBuffer
(
point
,
allowedDistance
Margin
)));
if
(
sourceLand
.
getFeatures
(
filterBuffered
).
size
()
>
0
)
{
return
"Coastal"
;
...
...
@@ -107,8 +106,8 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
return
"Land"
;
// }
}
else
{
throw
new
Exception
(
"Can't figure out the result for "
+
longitude
+
","
+
latitude
+
" with distance="
+
allowedDistance
FromLand
);
throw
new
Exception
(
"Can't figure out the result for
(
"
+
longitude
+
",
"
+
latitude
+
") with distance="
+
allowedDistance
Margin
);
}
}
catch
(
Exception
e
)
{
...
...
src/main/java/org/genesys/geotools/LonLatCacheKey.java
View file @
0347b867
...
...
@@ -58,14 +58,14 @@ public class LonLatCacheKey implements Serializable {
return
true
;
}
public
float
getLatitude
()
{
return
latitude
;
}
public
float
getLongitude
()
{
return
longitude
;
}
public
float
getLatitude
()
{
return
latitude
;
}
public
int
getAllowedDistanceMargin
()
{
return
allowedDistanceMargin
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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