Search in sources :

Example 1 with MapPoint

use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.

the class StyledConverter method addPoint.

private void addPoint(Node node, GType gt) {
    if (!clipper.contains(node.getLocation()))
        return;
    // to handle exit points we use a subclass of MapPoint
    // to carry some extra info (a reference to the
    // motorway associated with the exit)
    MapPoint mp;
    int type = gt.getType();
    if (type >= 0x2000 && type < 0x2800) {
        String ref = node.getTag(Exit.TAG_ROAD_REF);
        String id = node.getTag("mkgmap:osmid");
        if (ref != null) {
            String to = node.getTag(Exit.TAG_TO);
            MapExitPoint mep = new MapExitPoint(ref, to);
            String fd = node.getTag(Exit.TAG_FACILITY);
            if (fd != null)
                mep.setFacilityDescription(fd);
            if (id != null)
                mep.setOSMId(id);
            mp = mep;
        } else {
            mp = new MapPoint();
            if ("motorway_junction".equals(node.getTag("highway")))
                log.warn("Motorway exit", node.getName(), "(" + node.toBrowseURL() + ") has no (motorway) ref! (either make the exit share a node with the motorway or specify the motorway ref with a", Exit.TAG_ROAD_REF, "tag)");
        }
    } else {
        mp = new MapPoint();
    }
    elementSetup(mp, gt, node);
    mp.setLocation(node.getLocation());
    boolean dupPOI = checkDuplicatePOI(mp);
    if (dupPOI) {
        if (log.isInfoEnabled()) {
            if (FakeIdGenerator.isFakeId(node.getId()))
                log.info("ignoring duplicate POI with type", GType.formatType(type), mp.getName(), "for generated element with id", node.getId(), "at", mp.getLocation().toDegreeString());
            else
                log.info("ignoring duplicate POI with type", GType.formatType(type), mp.getName(), "for element", node.toBrowseURL());
        }
        return;
    }
    collector.addPoint(mp);
}
Also used : MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint)

Example 2 with MapPoint

use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.

the class AllElements method drawPoints.

private void drawPoints(MapCollector mapper, double slat, double slon, boolean hasBackground) {
    double lat = slat + 0.004;
    double lon = slon + 0.002;
    for (int maintype = 0; maintype <= MAX_POINT_TYPE; maintype++) {
        // for (int subtype = 0; subtype <= MAX_POINT_SUB_TYPE; subtype++) {
        for (int subtype = -1; subtype <= MAX_POINT_SUB_TYPE; subtype++) {
            // if maintype is zero, the subtype will be treated as the type
            // use subtype -1 to indicate no subtype and draw, say
            // point 0x23 under 0x2300 to check they are the same
            // The zero column is just for just to see 0x00
            // = (maintype << 8) + subtype;
            int type;
            if (subtype < 0)
                type = maintype;
            else
                type = (maintype << 8) + subtype;
            MapPoint point = new MapPoint();
            double baseLat = lat + subtype * ELEMENT_SPACING;
            double baseLong = lon + maintype * ELEMENT_SPACING;
            point.setMinResolution(10);
            if (subtype < 0 ? hasBackground : !hasBackground)
                point.setName(GType.formatType(type));
            point.setLocation(new Coord(baseLat, baseLong));
            point.setType(type);
            mapper.addPoint(point);
            if (configProps.containsKey("verbose"))
                System.out.println("Generated POI " + GType.formatType(type) + " at " + point.getLocation().toDegreeString());
            // XXX shouldn't be needed.
            mapper.addToBounds(point.getLocation());
            if (maintype == 0)
                break;
        }
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 3 with MapPoint

use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.

the class StyledConverterTest method makeConverter.

private StyledConverter makeConverter(String name) throws FileNotFoundException {
    Style style = new StyleImpl(LOC, name);
    MapCollector coll = new MapCollector() {

        public void addToBounds(Coord p) {
        }

        // could save points in the same way as lines to test them
        public void addPoint(MapPoint point) {
        }

        public void addLine(MapLine line) {
            // Save line so that it can be examined in the tests.
            assertNotNull("points are not null", line.getPoints());
            lines.add(line);
        }

        public void addShape(MapShape shape) {
        }

        public void addRoad(MapRoad road) {
            lines.add(road);
        }

        public int addRestriction(GeneralRouteRestriction grr) {
            return 0;
        }

        public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB) {
        }
    };
    return new StyledConverter(style, coll, new EnhancedProperties());
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) EnhancedProperties(uk.me.parabola.util.EnhancedProperties) MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) GeneralRouteRestriction(uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction) Style(uk.me.parabola.mkgmap.reader.osm.Style) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) MapCollector(uk.me.parabola.mkgmap.general.MapCollector) MapShape(uk.me.parabola.mkgmap.general.MapShape)

Example 4 with MapPoint

use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.

the class Locator method resolveIsInInfo.

/**
 * resolveIsInInfo tries to get country and region info out of the is_in field
 * @param p 	Point to process
 */
private void resolveIsInInfo(MapPoint p) {
    if (locationAutofill.contains("is_in") == false) {
        return;
    }
    if (p.getCountry() != null && p.getRegion() != null && p.getCity() == null) {
        p.setCity(p.getName());
        return;
    }
    if (p.getIsIn() != null) {
        String[] cityList = p.getIsIn().split(",");
        if (cityList.length > 1 && // Is last a continent ?
        isContinent(cityList[cityList.length - 1])) {
            if (p.getCountry() == null) {
                // The one before continent should be the country
                p.setCountry(normalizeCountry(cityList[cityList.length - 2].trim()));
            }
            // aks the config which info to use for region info
            int offset = locConfig.getRegionOffset(getCountryISOCode(p.getCountry())) + 1;
            if (cityList.length > offset && p.getRegion() == null)
                p.setRegion(cityList[cityList.length - (offset + 1)].trim());
        } else if (// Is first a continent ?
        cityList.length > 1 && isContinent(cityList[0])) {
            if (p.getCountry() == null) {
                // The one before continent should be the country
                p.setCountry(normalizeCountry(cityList[1].trim()));
            }
            int offset = locConfig.getRegionOffset(getCountryISOCode(p.getCountry())) + 1;
            if (cityList.length > offset && p.getRegion() == null)
                p.setRegion(cityList[offset].trim());
        } else if (p.getCountry() == null && cityList.length > 0) {
            // I don't like to check for a list of countries but I don't want other stuff in country field
            String isoCode = locConfig.getCountryISOCode(cityList[cityList.length - 1]);
            if (isoCode != null) {
                p.setCountry(normalizeCountry(isoCode));
                int offset = locConfig.getRegionOffset(isoCode) + 1;
                if (cityList.length > offset && p.getRegion() == null)
                    p.setRegion(cityList[cityList.length - (offset + 1)].trim());
            }
        }
    }
    if (p.getCountry() != null && p.getRegion() != null && p.getCity() == null) {
        p.setCity(p.getName());
    }
}
Also used : MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 5 with MapPoint

use of uk.me.parabola.mkgmap.general.MapPoint in project mkgmap by openstreetmap.

the class Locator method autofillCities.

public void autofillCities() {
    if (locationAutofill.contains("nearest") == false && locationAutofill.contains("is_in") == false) {
        return;
    }
    log.info("Locator City   Map contains", cityMap.size(), "entries");
    log.info("Locator Places Map contains", placesMap.size(), "entries");
    log.info("Locator Finder KdTree contains", cityFinder.size(), "entries");
    int runCount = 0;
    int maxRuns = 2;
    int unresCount;
    do {
        unresCount = 0;
        for (MapPoint place : placesMap) {
            if (place != null) {
                // first lets try exact name
                MapPoint near = findCityByIsIn(place);
                if (near == null) {
                // TODO perform a soundslike search
                }
                if (near != null) {
                    if (place.getCity() == null)
                        place.setCity(near.getCity());
                    if (place.getZip() == null)
                        place.setZip(near.getZip());
                } else if (locationAutofill.contains("nearest") && (runCount + 1) == maxRuns) {
                    // In the last resolve run just take info from the next
                    // known city
                    near = cityFinder.findNextPoint(place);
                    if (near != null && near.getCountry() != null) {
                        if (place.getCity() == null)
                            place.setCity(place.getName());
                    }
                }
                if (near != null) {
                    if (place.getRegion() == null)
                        place.setRegion(near.getRegion());
                    if (place.getCountry() == null)
                        place.setCountry(near.getCountry());
                }
                if (near == null)
                    unresCount++;
            }
        }
        for (int i = 0; i < placesMap.size(); i++) {
            MapPoint place = placesMap.get(i);
            if (place != null) {
                if (place.getCity() != null) {
                    addCity(place.getName(), place);
                    placesMap.set(i, null);
                } else if ((runCount + 1) == maxRuns) {
                    place.setCity(place.getName());
                    addCity(place.getName(), place);
                }
            }
        }
        runCount++;
        log.info("Locator City   Map contains", cityMap.size(), "entries after resolver run", runCount, "Still unresolved", unresCount);
    } while (unresCount > 0 && runCount < maxRuns);
}
Also used : MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Aggregations

MapPoint (uk.me.parabola.mkgmap.general.MapPoint)20 MapLine (uk.me.parabola.mkgmap.general.MapLine)8 Coord (uk.me.parabola.imgfmt.app.Coord)5 MapShape (uk.me.parabola.mkgmap.general.MapShape)5 LBLFile (uk.me.parabola.imgfmt.app.lbl.LBLFile)4 City (uk.me.parabola.imgfmt.app.lbl.City)3 Point (uk.me.parabola.imgfmt.app.trergn.Point)3 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)3 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)3 ArrayList (java.util.ArrayList)2 Area (uk.me.parabola.imgfmt.app.Area)2 POIRecord (uk.me.parabola.imgfmt.app.lbl.POIRecord)2 Zip (uk.me.parabola.imgfmt.app.lbl.Zip)2 Test (org.junit.Test)1 Exit (uk.me.parabola.imgfmt.app.Exit)1 Label (uk.me.parabola.imgfmt.app.Label)1 Country (uk.me.parabola.imgfmt.app.lbl.Country)1 Region (uk.me.parabola.imgfmt.app.lbl.Region)1 GeneralRouteRestriction (uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction)1 Numbers (uk.me.parabola.imgfmt.app.net.Numbers)1