Search in sources :

Example 1 with Geocoding

use of org.opensextant.data.Geocoding in project Xponents by OpenSextant.

the class CoordinateAssociationRule method evaluate.

/**
     * If a particular geo is close to a candidate name/location, then add to
     * the candidate's score for that location.
     */
@Override
public void evaluate(PlaceCandidate name, Place geo) {
    if (!isRelevant()) {
        return;
    }
    if (name.isCountry) {
        return;
    }
    switch(associationScheme) {
        case HAVERSINE:
            // score up geo appropriately
            for (Geocoding ll : coordinates) {
                long meters = GeodeticUtility.distanceMeters(ll, geo);
                // is within
                if (meters < DEFAULT_THRESHOLD_METERS) {
                    double proximityScore = (float) (DEFAULT_THRESHOLD_METERS - meters) / DEFAULT_THRESHOLD_METERS;
                    name.addGeocoordEvidence(COORD_PROXIMITY_RULE, weight, ll, geo, proximityScore);
                }
            }
            break;
        default:
        case GEOHASH:
            // if geohash geo matches one ore more coordinates,
            // score up geo appropriately.
            String geo_gh = GeohashUtils.encodeLatLon(geo.getLatitude(), geo.getLongitude());
            String grid = geo_gh.substring(0, DEFAULT_THRESHOLD_DIGITS);
            for (Geocoding ll : coordinates) {
                String gh = GeohashUtils.encodeLatLon(ll.getLatitude(), ll.getLongitude());
                // is within
                if (gh.startsWith(grid)) {
                    name.addGeocoordEvidence(GEOHASH_CONTAINS_RULE, weight, ll, geo, 1.0);
                }
            }
            break;
    }
}
Also used : Geocoding(org.opensextant.data.Geocoding)

Example 2 with Geocoding

use of org.opensextant.data.Geocoding in project Xponents by OpenSextant.

the class GISDataFormatter method writeGeocodingResult.

/**
     * Implementation of adding info extraction/geocoding restults to GIS outputs.
     */
@Override
public void writeGeocodingResult(ExtractionResult rowdata) {
    boolean error = false;
    log.debug("Adding data for File {} Count={}", rowdata.recordFile, rowdata.matches.size());
    for (TextMatch g : rowdata.matches) {
        if (filterOut(g)) {
            continue;
        }
        // Increment ID
        id++;
        // Only TextMatches that implement the Geocoding interface are
        // allowed here:
        Geocoding geocoding = getGeocoding(g);
        if (geocoding == null) {
            log.debug("Non-geo will be ignored: {}", g);
            continue;
        }
        log.debug("Add {}#{}", id, g);
        try {
            for (Feature row : gisDataModel.buildRows(id, geocoding, g, rowdata.attributes, rowdata)) {
                log.debug("FEATURE: {}", row);
                this.os.write(row);
            }
        } catch (ConfigException fieldErr) {
            if (!error) {
                log.error("OUTPUTTER, ERR=" + fieldErr);
            }
            error = true;
        }
    }
}
Also used : ConfigException(org.opensextant.ConfigException) TextMatch(org.opensextant.extraction.TextMatch) Geocoding(org.opensextant.data.Geocoding) Feature(org.opensextant.giscore.events.Feature)

Aggregations

Geocoding (org.opensextant.data.Geocoding)2 ConfigException (org.opensextant.ConfigException)1 TextMatch (org.opensextant.extraction.TextMatch)1 Feature (org.opensextant.giscore.events.Feature)1