Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
validator.genesys-pgr.org
Commits
c36a482d
Commit
c36a482d
authored
Apr 18, 2019
by
Matija Obreza
Browse files
Suggest coordinates that fit ORIGCTY
parent
c6188c3c
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys/taxonomy/checker/web/service/impl/CountryProcessServiceImpl.java
View file @
c36a482d
...
...
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
com.opencsv.CSVReader
;
import
com.vividsolutions.jts.geom.Coordinate
;
/**
* @author Andrey Lugovskoy.
...
...
@@ -82,15 +83,27 @@ public class CountryProcessServiceImpl implements ProcessService {
outputHeaders
.
add
(
pos
+
1
,
ApplicationUtils
.
HEADER_ORIGCTY_DISTANCE
);
outputMapping
.
add
(
pos
+
1
,
null
);
}
// Add extra header HEADER_DECLATITUDE_
CHECK
// Add extra header HEADER_DECLATITUDE_
PARSED
{
final
int
pos
=
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_LATITUDE
);
outputHeaders
.
add
(
pos
+
1
,
ApplicationUtils
.
HEADER_DECLATITUDE_PARSED
);
outputMapping
.
add
(
pos
+
1
,
null
);
}
// Add extra header HEADER_DECLATITUDE_CHECK
{
final
int
pos
=
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLATITUDE_PARSED
);
outputHeaders
.
add
(
pos
+
1
,
ApplicationUtils
.
HEADER_DECLATITUDE_CHECK
);
outputMapping
.
add
(
pos
+
1
,
null
);
}
// Add extra header HEADER_DECLONGITUDE_
CHECK
// Add extra header HEADER_DECLONGITUDE_
PARSED
{
final
int
pos
=
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_LONGITUDE
);
outputHeaders
.
add
(
pos
+
1
,
ApplicationUtils
.
HEADER_DECLONGITUDE_PARSED
);
outputMapping
.
add
(
pos
+
1
,
null
);
}
// Add extra header HEADER_DECLONGITUDE_CHECK
{
final
int
pos
=
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLONGITUDE_PARSED
);
outputHeaders
.
add
(
pos
+
1
,
ApplicationUtils
.
HEADER_DECLONGITUDE_CHECK
);
outputMapping
.
add
(
pos
+
1
,
null
);
}
...
...
@@ -158,6 +171,8 @@ public class CountryProcessServiceImpl implements ProcessService {
String
result
=
null
;
String
distance
=
null
;
String
newlatitude
=
null
;
String
newlongitude
=
null
;
// if ("101346".equals(nextLine[0])) {
// LOG.info("!!! Got what we're looking for");
// }
...
...
@@ -180,15 +195,24 @@ public class CountryProcessServiceImpl implements ProcessService {
if
(
origCty
!=
null
&&
!
result
.
equals
(
origCty
))
{
try
{
distance
=
""
+
(
long
)
countryOfOriginService
.
distanceToBorder
(
longitude
,
latitude
,
origCty
);
double
distanceToBorder
=
countryOfOriginService
.
distanceToBorder
(
longitude
,
latitude
,
origCty
);
distance
=
""
+
(
long
)
distanceToBorder
;
}
catch
(
final
Throwable
e
)
{
distance
=
"ERROR: "
+
e
.
getMessage
();
}
Coordinate
fixed
=
fixCoordinates
(
longitude
,
latitude
,
origCty
,
true
);
if
(
fixed
!=
null
)
{
newlatitude
=
decimalFormat
.
format
(
fixed
.
y
);
newlongitude
=
decimalFormat
.
format
(
fixed
.
x
);
}
}
try
{
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLATITUDE_
CHECK
)]
=
decimalFormat
.
format
(
latitude
);
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLONGITUDE_
CHECK
)]
=
decimalFormat
.
format
(
longitude
);
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLATITUDE_
PARSED
)]
=
decimalFormat
.
format
(
latitude
);
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLONGITUDE_
PARSED
)]
=
decimalFormat
.
format
(
longitude
);
}
catch
(
final
Throwable
e
)
{
LOG
.
error
(
e
.
getMessage
(),
e
);
}
...
...
@@ -196,13 +220,18 @@ public class CountryProcessServiceImpl implements ProcessService {
LOG
.
error
(
"Unparsable lat/lon from ({}, {})"
,
declongitude
,
declatitude
,
e
);
result
=
"Unparseable lat/lon: "
+
e
.
getMessage
();
}
catch
(
final
Throwable
e
)
{
LOG
.
error
(
"Error parsing lat/lon: {}"
,
e
.
getMessage
());
LOG
.
error
(
"Error parsing lat/lon: {}"
,
e
.
getMessage
()
,
e
);
result
=
"ERROR: "
+
e
.
getMessage
();
}
}
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_ORIGCTY_CHECK
)]
=
StringUtils
.
equals
(
origCty
,
result
)
?
ApplicationUtils
.
CHECK_PASSED
:
result
;
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_ORIGCTY_DISTANCE
)]
=
distance
;
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLATITUDE_CHECK
)]
=
newlatitude
;
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLONGITUDE_CHECK
)]
=
newlongitude
;
lines
.
add
(
outputLine
);
// if ("101346".equals(nextLine[0])) {
// LOG.info("Written what we're looking for");
...
...
@@ -238,4 +267,64 @@ public class CountryProcessServiceImpl implements ProcessService {
// }
return
lines
;
}
/**
* Check if coordinates fall into the country or try the common fixes (swap,
* flip) to make values fit.
*
* @param longitude Original longitude
* @param latitude Original latitude
* @param origCty Country code (required)
* @param swap Try swapping?
* @return
*/
protected
Coordinate
fixCoordinates
(
float
longitude
,
float
latitude
,
final
String
origCty
,
boolean
swap
)
{
if
(
origCty
==
null
)
{
return
null
;
}
try
{
// Check originals
float
lon
=
longitude
;
float
lat
=
latitude
;
String
result
=
countryOfOriginService
.
getCountries
(
lon
,
lat
,
origCty
,
ApplicationUtils
.
ALLOWED_DISTANCE_MARGIN
);
if
(
StringUtils
.
equals
(
result
,
origCty
))
{
return
new
Coordinate
(
lon
,
lat
);
}
// Flip only longitude
lon
=
-
longitude
;
lat
=
latitude
;
result
=
countryOfOriginService
.
getCountries
(
lon
,
lat
,
origCty
,
ApplicationUtils
.
ALLOWED_DISTANCE_MARGIN
);
if
(
StringUtils
.
equals
(
result
,
origCty
))
{
return
new
Coordinate
(
lon
,
lat
);
}
// Flip latitude & longitude
lon
=
-
longitude
;
lat
=
-
latitude
;
result
=
countryOfOriginService
.
getCountries
(
lon
,
lat
,
origCty
,
ApplicationUtils
.
ALLOWED_DISTANCE_MARGIN
);
if
(
StringUtils
.
equals
(
result
,
origCty
))
{
return
new
Coordinate
(
lon
,
lat
);
}
// Flip only latitude
lon
=
longitude
;
lat
=
-
latitude
;
result
=
countryOfOriginService
.
getCountries
(
lon
,
lat
,
origCty
,
ApplicationUtils
.
ALLOWED_DISTANCE_MARGIN
);
if
(
StringUtils
.
equals
(
result
,
origCty
))
{
return
new
Coordinate
(
lon
,
lat
);
}
// Swap
if
(
swap
)
{
return
fixCoordinates
(
latitude
,
longitude
,
origCty
,
false
);
}
}
catch
(
Exception
e
)
{
LOG
.
error
(
e
.
getMessage
(),
e
);
}
return
null
;
}
}
src/main/java/org/genesys/taxonomy/checker/web/service/impl/LandOrSeaProcessServiceImpl.java
View file @
c36a482d
...
...
@@ -73,21 +73,21 @@ public class LandOrSeaProcessServiceImpl implements ProcessService {
final
Map
<
String
,
Integer
>
sourceMapping
=
HeaderUtils
.
makeSourceMapping
(
headers
,
new
String
[]
{
ApplicationUtils
.
HEADER_LONGITUDE
,
ApplicationUtils
.
HEADER_LATITUDE
});
// Add extra header HEADER_DECLATITUDE_
CHECK
// Add extra header HEADER_DECLATITUDE_
PARSED
{
final
int
pos
=
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_LATITUDE
);
outputHeaders
.
add
(
pos
+
1
,
ApplicationUtils
.
HEADER_DECLATITUDE_
CHECK
);
outputHeaders
.
add
(
pos
+
1
,
ApplicationUtils
.
HEADER_DECLATITUDE_
PARSED
);
outputMapping
.
add
(
pos
+
1
,
null
);
}
// Add extra header HEADER_DECLONGITUDE_
CHECK
// Add extra header HEADER_DECLONGITUDE_
PARSED
{
final
int
pos
=
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_LONGITUDE
);
outputHeaders
.
add
(
pos
+
1
,
ApplicationUtils
.
HEADER_DECLONGITUDE_
CHECK
);
outputHeaders
.
add
(
pos
+
1
,
ApplicationUtils
.
HEADER_DECLONGITUDE_
PARSED
);
outputMapping
.
add
(
pos
+
1
,
null
);
}
// Add extra header HEADER_LANDORSEA_CHECK
{
final
int
pos
=
Math
.
max
(
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLONGITUDE_
CHECK
),
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLATITUDE_
CHECK
));
final
int
pos
=
Math
.
max
(
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLONGITUDE_
PARSED
),
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLATITUDE_
PARSED
));
outputHeaders
.
add
(
pos
+
1
,
ApplicationUtils
.
HEADER_LANDORSEA_CHECK
);
outputMapping
.
add
(
pos
+
1
,
null
);
}
...
...
@@ -163,8 +163,8 @@ public class LandOrSeaProcessServiceImpl implements ProcessService {
result
=
landOrSeaService
.
classifyLocation
(
longitude
,
latitude
,
ApplicationUtils
.
ALLOWED_DISTANCE_MARGIN
);
try
{
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLATITUDE_
CHECK
)]
=
decimalFormat
.
format
(
latitude
);
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLONGITUDE_
CHECK
)]
=
decimalFormat
.
format
(
longitude
);
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLATITUDE_
PARSED
)]
=
decimalFormat
.
format
(
latitude
);
outputLine
[
outputHeaders
.
indexOf
(
ApplicationUtils
.
HEADER_DECLONGITUDE_
PARSED
)]
=
decimalFormat
.
format
(
longitude
);
}
catch
(
final
Throwable
e
)
{
LOG
.
error
(
e
.
getMessage
(),
e
);
}
...
...
src/main/java/org/genesys/taxonomy/checker/web/util/ApplicationUtils.java
View file @
c36a482d
...
...
@@ -82,8 +82,10 @@ public class ApplicationUtils {
/** The Constant HEADER_LANDORSEA_CHECK. */
public
static
final
String
HEADER_LANDORSEA_CHECK
=
"LANDorSEA_check"
;
public
static
final
String
HEADER_DECLATITUDE_CHECK
=
"DECLATITUDE_parsed"
;
public
static
final
String
HEADER_DECLATITUDE_PARSED
=
"DECLATITUDE_parsed"
;
public
static
final
String
HEADER_DECLATITUDE_CHECK
=
"DECLATITUDE_check"
;
public
static
final
String
HEADER_DECLONGITUDE_CHECK
=
"DECLONGITUDE_parsed"
;
public
static
final
String
HEADER_DECLONGITUDE_PARSED
=
"DECLONGITUDE_parsed"
;
public
static
final
String
HEADER_DECLONGITUDE_CHECK
=
"DECLONGITUDE_check"
;
}
src/main/webapp/WEB-INF/jsp/result.jsp
View file @
c36a482d
...
...
@@ -46,6 +46,8 @@
.x-ORIGCTY_distance
,
.x-DECLATITUDE_parsed
,
.x-DECLONGITUDE_parsed
,
.x-DECLATITUDE_check
,
.x-DECLONGITUDE_check
,
.x-LANDorSEA_check
{
background-color
:
#ffffca
;
}
...
...
@@ -60,6 +62,8 @@
thead
.x-ORIGCTY_distance
,
thead
.x-DECLATITUDE_parsed
,
thead
.x-DECLONGITUDE_parsed
,
thead
.x-DECLATITUDE_check
,
thead
.x-DECLONGITUDE_check
,
thead
.x-LANDorSEA_check
{
background-color
:
Yellow
;
}
...
...
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