Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gisgraphy Geocoder #34

Merged
merged 10 commits into from
Feb 22, 2018
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GraphHopper Geocoder Converter

Converts a geocoding response like from Nominatim or OpenCageData to a GraphHopper response.
Converts a geocoding response like from Nominatim, Gisgraphy, or OpenCageData to a GraphHopper response.
A user queries this API and the converter is then querying Nominatim getting the corresponding response and converting it to the GraphHopper response layout.

[![Build Status](https://travis-ci.org/graphhopper/geocoder-converter.svg?branch=master)](https://travis-ci.org/graphhopper/geocoder-converter)
Expand Down Expand Up @@ -117,6 +117,16 @@ These examples are taken from:
- https://graphhopper.com/api/1/docs/geocoding/#example-output-for-the-case-typejson
- https://wiki.openstreetmap.org/wiki/Nominatim#Examples

## Input parameters
### For Gisgraphy, the converter accepts the following parameters:
* q (required for forward geocoding) : the text search query
* point (required for reverse geocoding) : point to search arround for reverse geocoding or to do location bias for forward geocoding and auto-completion
* radius : radius in meter to do search in a bounding circle
* country : an iso-3166-2 country code (e.g : DE) filter the results to the specify country code
* limit : limit the number of results
* reverse : true or false, wether we do a reverse or forward geocoding search
* autocomplete : true or false. wether we do an search for auto-completion.


## Starting the Server

Expand Down
11 changes: 8 additions & 3 deletions converter.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
nominatimUrl: http://nominatim.openstreetmap.org/search/
nominatimReverseUrl: http://nominatim.openstreetmap.org/reverse/
nominatimURL: http://nominatim.openstreetmap.org/search/
nominatimReverseURL: http://nominatim.openstreetmap.org/reverse/
nominatim: true
nominatimEmail:

openCageDataUrl: https://api.opencagedata.com/geocode/v1/json
openCageDataURL: https://api.opencagedata.com/geocode/v1/json
openCageDataKey:
openCageData: false

gisgraphyGeocodingURL: https://services.gisgraphy.com/geocoding/
gisgraphyReverseGeocodingURL: https://services.gisgraphy.com/reversegeocoding/
gisgraphySearchURL: https://services.gisgraphy.com/fulltext/
gisgraphyAPIKey:

# e.g. to restrict for local access
# ipWhiteList:"localhost,127.0.0.1"
ipWhiteList: ""
22 changes: 15 additions & 7 deletions src/main/java/com/graphhopper/converter/ConverterApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.graphhopper.converter.api.IPFilter;
import com.graphhopper.converter.health.NominatimHealthCheck;
import com.graphhopper.converter.resources.ConverterResourceGisgraphy;
import com.graphhopper.converter.resources.ConverterResourceNominatim;
import com.graphhopper.converter.resources.ConverterResourceOpenCageData;

import io.dropwizard.Application;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.client.JerseyClientConfiguration;
Expand All @@ -13,21 +15,21 @@

import javax.servlet.DispatcherType;
import javax.ws.rs.client.Client;

import java.util.EnumSet;

/**
* @author Robin Boldt
* @author Robin Boldt,David Masclet
*/
public class ConverterApplication extends Application<ConverterConfiguration> {

public static void main(String[] args) throws Exception {
new ConverterApplication().run(args);
}


@Override
public String getName() {
return "graphhopper-nominatim-converter";
return "graphhopper-geocoder-converter";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch, thanks :)

}

@Override
Expand All @@ -48,22 +50,28 @@ public void run(ConverterConfiguration converterConfiguration, Environment envir

if (converterConfiguration.isNominatim()) {
final ConverterResourceNominatim resource = new ConverterResourceNominatim(
converterConfiguration.getNominatimUrl(),
converterConfiguration.getNominatimReverseUrl(),
converterConfiguration.getNominatimURL(),
converterConfiguration.getNominatimReverseURL(),
converterConfiguration.getNominatimEmail(),
client);
environment.jersey().register(resource);
}

if (converterConfiguration.isOpenCageData()) {
final ConverterResourceOpenCageData resource = new ConverterResourceOpenCageData(
converterConfiguration.getOpenCageDataUrl(), converterConfiguration.getOpenCageDataKey(), client);
converterConfiguration.getOpenCageDataURL(), converterConfiguration.getOpenCageDataKey(), client);
environment.jersey().register(resource);
}

if (converterConfiguration.isGisgraphy()) {
final ConverterResourceGisgraphy resource = new ConverterResourceGisgraphy(
converterConfiguration.getGisgraphyGeocodingURL(), converterConfiguration.getGisgraphyReverseGeocodingURL(),converterConfiguration.getGisgraphySearchURL(),converterConfiguration.getGisgraphyAPIKey(), client);
environment.jersey().register(resource);
}

if (converterConfiguration.isHealthCheck()) {
final NominatimHealthCheck healthCheck =
new NominatimHealthCheck(converterConfiguration.getNominatimUrl(), client);
new NominatimHealthCheck(converterConfiguration.getNominatimURL(), client);
environment.healthChecks().register("template", healthCheck);
}

Expand Down
91 changes: 75 additions & 16 deletions src/main/java/com/graphhopper/converter/ConverterConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,31 @@
import javax.validation.constraints.NotNull;

/**
* @author Robin Boldt
* @author Robin Boldt, David Masclet
*/
public class ConverterConfiguration extends Configuration {

@NotEmpty
private String nominatimUrl = "http://nominatim.openstreetmap.org/search/";
private String nominatimURL = "http://nominatim.openstreetmap.org/search/";
@NotEmpty
private String nominatimReverseUrl = "http://nominatim.openstreetmap.org/reverse/";
private String nominatimReverseURL = "http://nominatim.openstreetmap.org/reverse/";
private String nominatimEmail = "";
private String openCageDataUrl = "https://api.opencagedata.com/geocode/v1/json";

private String openCageDataURL = "https://api.opencagedata.com/geocode/v1/json";
private String openCageDataKey = "";

private String gisgraphyGeocodingURL = "https://services.gisgraphy.com/geocoding/";
private String gisgraphyReverseGeocodingURL ="https://services.gisgraphy.com/reversegeocoding/";
private String gisgraphySearchURL = "https://services.gisgraphy.com/fulltext/";
private String gisgraphyAPIKey="";

@Valid
@NotNull
private final JerseyClientConfiguration jerseyClient = new JerseyClientConfiguration();

private boolean healthCheck = true;
private boolean nominatim = true;
private boolean gisgraphy = true;
private boolean opencagedata;

private String ipBlackList = "";
Expand All @@ -43,13 +50,13 @@ public boolean isNominatim() {
}

@JsonProperty
public String getNominatimUrl() {
return nominatimUrl;
public String getNominatimURL() {
return nominatimURL;
}

@JsonProperty
public void setNominatimUrl(String url) {
this.nominatimUrl = url;
public void setNominatimURL(String url) {
this.nominatimURL = url;
}

@JsonProperty
Expand All @@ -73,13 +80,13 @@ public boolean isOpenCageData() {
}

@JsonProperty
public String getOpenCageDataUrl() {
return openCageDataUrl;
public String getOpenCageDataURL() {
return openCageDataURL;
}

@JsonProperty
public void setOpenCageDataUrl(String url) {
this.openCageDataUrl = url;
public void setOpenCageDataURL(String url) {
this.openCageDataURL = url;
}

@JsonProperty
Expand Down Expand Up @@ -127,11 +134,63 @@ public void setIPWhiteList(String ipWhiteList) {
this.ipWhiteList = ipWhiteList;
}

public String getNominatimReverseUrl() {
return nominatimReverseUrl;
@JsonProperty
public String getNominatimReverseURL() {
return nominatimReverseURL;
}

@JsonProperty
public void setNominatimReverseURL(String nominatimReverseURL) {
this.nominatimReverseURL = nominatimReverseURL;
}

@JsonProperty
public String getGisgraphyGeocodingURL() {
return gisgraphyGeocodingURL;
}

@JsonProperty
public void setGisgraphyGeocodingURL(String gisgraphyGeocodingURL) {
this.gisgraphyGeocodingURL = gisgraphyGeocodingURL;
}

@JsonProperty
public String getGisgraphyReverseGeocodingURL() {
return gisgraphyReverseGeocodingURL;
}

@JsonProperty
public void setGisgraphyReverseGeocodingURL(String gisgraphyReverseGeocodingURL) {
this.gisgraphyReverseGeocodingURL = gisgraphyReverseGeocodingURL;
}

public void setNominatimReverseUrl(String nominatimReverseUrl) {
this.nominatimReverseUrl = nominatimReverseUrl;
@JsonProperty
public String getGisgraphySearchURL() {
return gisgraphySearchURL;
}

@JsonProperty
public void setGisgraphySearchURL(String gisgraphySearchURL) {
this.gisgraphySearchURL = gisgraphySearchURL;
}

@JsonProperty
public String getGisgraphyAPIKey() {
return gisgraphyAPIKey;
}

@JsonProperty
public void setGisgraphyAPIKey(String gisgraphyAPIKey) {
this.gisgraphyAPIKey = gisgraphyAPIKey;
}

@JsonProperty
public boolean isGisgraphy() {
return gisgraphy;
}

@JsonProperty
public void setGisgraphy(boolean gisgraphy) {
this.gisgraphy = gisgraphy;
}
}
Loading