All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.evasion.plugin.geoloc.dataimport.geoname.GeonameParser Maven / Gradle / Ivy

There is a newer version: 2.0.0.2
Show newest version
/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package com.evasion.plugin.geoloc.dataimport.geoname;

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 GeonameParser extends AbstractFileParser {

    public static final String FORMAT = "geoname";

    public GeonameParser(File file) {
        super(file);
    }

    @Override
    protected EntityJPA traiterLigne(String[] ligne) {
        EntityJPA result = null;
        if (DesignationCode.ADM1.equals(ligne[GeonameFormat.FEATURE_CODE])) {
            result = createRegionAdm(ligne);
        } else if (DesignationCode.PPL.equals(ligne[GeonameFormat.FEATURE_CODE]) || DesignationCode.PPLA.equals(ligne[GeonameFormat.FEATURE_CODE])) {
            result = createCity(ligne);
        }
        return result;
    }

    private AdminDivision createRegionAdm(String[] ligne) {
        AdminDivision region = new AdminDivision(ligne[GeonameFormat.ADM1], createPartialCountry(ligne), createLocation(ligne));
        region.setName(ligne[GeonameFormat.NAME]);
        region.setGeoname(new Geoname(Integer.parseInt(ligne[GeonameFormat.GEONAME_ID]), formatStringToDate(ligne[GeonameFormat.MODIFICATION_DATE])));
        return region;
    }

    private Country createPartialCountry(String[] ligne) {
        return new Country(null, ligne[GeonameFormat.COUNTRY_CODE], null);
    }

    private Location createLocation(String[] ligne) {
        Location location = new Location(ligne[GeonameFormat.NAME], Double.parseDouble(ligne[GeonameFormat.LATITUDE]), Double.parseDouble(ligne[GeonameFormat.LONGITUDE]));
        if (!ligne[GeonameFormat.ALTITUDE].isEmpty()) {
            location.setAltitude(Integer.parseInt(ligne[GeonameFormat.ALTITUDE]));
        }
        return location;
    }

    private City createCity(String[] ligne) {
        City city = new City(createPartialCountry(ligne), createLocation(ligne));
        city.setGeoname(new Geoname(Integer.parseInt(ligne[GeonameFormat.GEONAME_ID]), formatStringToDate(ligne[GeonameFormat.MODIFICATION_DATE])));
        return city;
    }

    @Override
    public int getNbrColomnRef() {
        return GeonameFormat.SIZE_COLUMN_FILE;
    }

    @Override
    public String separateurColumn() {
        return "\t";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy