com.evasion.plugin.geoloc.dataimport.gis.GISParser Maven / Gradle / Ivy
The newest version!
/*
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
package com.evasion.plugin.geoloc.dataimport.gis;
import com.evasion.EntityJPA;
import com.evasion.entity.geolocation.*;
import com.evasion.plugin.geoloc.dataimport.AbstractFileParser;
import com.evasion.plugin.geoloc.dataimport.DesignationCode;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
/**
*
* @author glon-56610
*/
public class GISParser extends AbstractFileParser {
public static final String FORMAT = "GIS";
public GISParser(File file) {
super(file);
}
@Override
protected EntityJPA traiterLigne(String[] ligne) {
EntityJPA result = null;
if ("A".equalsIgnoreCase(ligne[GISFormat.FC]) && DesignationCode.ADM1.equals(ligne[GISFormat.DSG]) && (ligne[GISFormat.NT].isEmpty() || "N".equalsIgnoreCase(ligne[GISFormat.NT]))) {
result = createRegionAdm(ligne);
} else if ("P".equalsIgnoreCase(ligne[GISFormat.FC]) && DesignationCode.PPL.startsWith(ligne[GISFormat.DSG]) && (ligne[GISFormat.NT].isEmpty() || "N".equalsIgnoreCase(ligne[GISFormat.NT]))) {
result = createCity(ligne);
}
return result;
}
private AdminDivision createRegionAdm(String[] ligne) {
AdminDivision region = new AdminDivision(ligne[GISFormat.ADM1], createPartialCountry(ligne), createLocation(ligne));
region.setName(ligne[GISFormat.FULL_NAME_RO]);
region.setGeoname(new Geoname(Integer.parseInt(ligne[GISFormat.UFI]), formatStringToDate(ligne[GISFormat.MODIFY_DATE])));
return region;
}
private Location createLocation(String[] ligne) {
Location location = new Location(ligne[GISFormat.FULL_NAME_RO], Double.parseDouble(ligne[GISFormat.LAT]), Double.parseDouble(ligne[GISFormat.LONG]));
if (!ligne[GISFormat.ELEV].isEmpty()) {
location.setAltitude(Integer.parseInt(ligne[GISFormat.ELEV]));
}
return location;
}
private Country createPartialCountry(String[] ligne) {
return new Country(null, ligne[GISFormat.CC1], null);
}
private City createCity(String[] ligne) {
City city = new City(createPartialCountry(ligne), createLocation(ligne));
city.setGeoname(new Geoname(Integer.parseInt(ligne[GISFormat.UFI]), formatStringToDate(ligne[GISFormat.MODIFY_DATE])));
return city;
}
@Override
public int getNbrColomnRef() {
return GISFormat.SIZE_COLUMN_FILE;
}
@Override
public String separateurColumn() {
return "\t";
}
}