Skip to content
Snippets Groups Projects
Commit d5e29c94 authored by Bertrand PINEL's avatar Bertrand PINEL
Browse files

Add ingestion of geonames french cities

parent 61014e92
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,10 @@ import fr.ippon.geohipster.web.rest.util.HeaderUtil; ...@@ -7,6 +7,10 @@ import fr.ippon.geohipster.web.rest.util.HeaderUtil;
import fr.ippon.geohipster.web.rest.util.PaginationUtil; import fr.ippon.geohipster.web.rest.util.PaginationUtil;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import io.github.jhipster.web.util.ResponseUtil; import io.github.jhipster.web.util.ResponseUtil;
import org.geolatte.geom.G2D;
import org.geolatte.geom.Point;
import org.geolatte.geom.Position;
import org.geolatte.geom.crs.CrsRegistry;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
...@@ -16,6 +20,10 @@ import org.springframework.http.HttpStatus; ...@@ -16,6 +20,10 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
...@@ -33,6 +41,8 @@ public class GeocityResource { ...@@ -33,6 +41,8 @@ public class GeocityResource {
private static final String ENTITY_NAME = "geocity"; private static final String ENTITY_NAME = "geocity";
private static final String FRGeonamesCityFile = "/geonames/cities_fr.csv";
private final GeocityService geocityService; private final GeocityService geocityService;
public GeocityResource(GeocityService geocityService) { public GeocityResource(GeocityService geocityService) {
...@@ -123,4 +133,51 @@ public class GeocityResource { ...@@ -123,4 +133,51 @@ public class GeocityResource {
geocityService.delete(id); geocityService.delete(id);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
} }
@GetMapping("/loadGeoNamesCities")
public void loadGeoNamesCities(){
log.info("Loading GeoName file "+FRGeonamesCityFile);
InputStream stream = this.getClass().getResourceAsStream(FRGeonamesCityFile);
try (BufferedReader br = new BufferedReader(new InputStreamReader(stream))) {
String sCurrentLine;
int nbCities = 0;
while ((sCurrentLine = br.readLine()) != null) {
String[] columns = sCurrentLine.split("\t");
if (columns[7].startsWith("PPL")){
Geocity geocity = new Geocity();
geocity.setName(columns[1]);
geocity.setAsciiname(columns[2]);
geocity.setAlternatenames(columns[3]);
Position g2d = new G2D(new Double(columns[5]), new Double(columns[4]));
Point point = new Point(g2d, CrsRegistry.getCoordinateReferenceSystemForEPSG(4326, null));
geocity.setLocation(point);
geocity.setFeatureclass(columns[6]);
geocity.setFeaturetype(columns[7]);
geocity.setCountrycode(columns[8]);
geocity.setCc2(columns[9]);
geocity.setAdmin1code(columns[10]);
geocity.setAdmin2code(columns[11]);
geocity.setAdmin3code(columns[12]);
geocity.setAdmin4code(columns[13]);
geocity.setPopulation(new Integer(columns[14]));
if (columns[15].trim().length()==0)
geocity.setElevation(0);
else
geocity.setElevation(new Integer(columns[15]));
geocity.setDem(columns[16]);
geocityService.save(geocity);
nbCities++;
}
}
log.info("Cities uploaded : "+nbCities);
} catch (IOException e) {
e.printStackTrace();
}
}
} }
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<column name="asciiname" type="varchar(255)"> <column name="asciiname" type="varchar(255)">
<constraints nullable="true" /> <constraints nullable="true" />
</column> </column>
<column name="alternatenames" type="varchar(255)"> <column name="alternatenames" type="varchar(1000)">
<constraints nullable="true" /> <constraints nullable="true" />
</column> </column>
<column name="location" type="geometry(Point, 4326)"/> <column name="location" type="geometry(Point, 4326)"/>
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment