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: ""
109 changes: 59 additions & 50 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,60 +15,67 @@

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";
}

@Override
public void initialize(Bootstrap<ConverterConfiguration> bootstrap) {
// nothing to do yet
}

@Override
public void run(ConverterConfiguration converterConfiguration, Environment environment) throws Exception {

JerseyClientConfiguration cfg = converterConfiguration.getJerseyClientConfiguration();
cfg.setTimeout(Duration.seconds(10));
cfg.setConnectionTimeout(Duration.seconds(10));
cfg.setConnectionRequestTimeout(Duration.seconds(10));

final Client client = new JerseyClientBuilder(environment).using(cfg)
.build(getName());

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

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

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

environment.servlets().addFilter("ip-filter", new IPFilter(converterConfiguration.getIPWhiteList(), converterConfiguration.getIPBlackList())).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
}
public static void main(String[] args) throws Exception {
new ConverterApplication().run(args);
}


Copy link
Member

Choose a reason for hiding this comment

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

Would you mind to check the formatting? Sometimes there are 2 or 3 lines between methods. Is there a reason for this or can we just use one empty line?

Copy link
Member

Choose a reason for hiding this comment

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

Also there is a change for this whole file, probably because of tabs vs spaces. It would be great if we could keep the changeset as small as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please do it separately. I use Eclipse and appreciate if you can do it in another commit. thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I done it but not sure it is correct

@Override
public String getName() {
return "graphhopper-geocoder-converter";
}

@Override
public void initialize(Bootstrap<ConverterConfiguration> bootstrap) {
// nothing to do yet
}

@Override
public void run(ConverterConfiguration converterConfiguration, Environment environment) throws Exception {

JerseyClientConfiguration cfg = converterConfiguration.getJerseyClientConfiguration();
cfg.setTimeout(Duration.seconds(10));
cfg.setConnectionTimeout(Duration.seconds(10));
cfg.setConnectionRequestTimeout(Duration.seconds(10));

final Client client = new JerseyClientBuilder(environment).using(cfg)
.build(getName());

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

if (converterConfiguration.isOpenCageData()) {
final ConverterResourceOpenCageData resource = new ConverterResourceOpenCageData(
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);
environment.healthChecks().register("template", healthCheck);
}

environment.servlets().addFilter("ip-filter", new IPFilter(converterConfiguration.getIPWhiteList(), converterConfiguration.getIPBlackList())).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
}
}
Loading