com.nextgis.maplib.datasource.GeoPolygon Java Examples

The following examples show how to use com.nextgis.maplib.datasource.GeoPolygon. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimplePolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onDraw(GeoGeometry geoGeometry, GISDisplay display) {
    Float textSize = (null == mTextSize) ? null : 12f;
    float scaledTextSize = (float) (mTextSize * (mWidth / display.getScale()));
    GeoPoint center = geoGeometry.getEnvelope().getCenter();
    switch (geoGeometry.getType()) {
        case GTPolygon:
            drawPolygon((GeoPolygon) geoGeometry, display);
            drawText(scaledTextSize, center, display);
            break;
        case GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) geoGeometry;

            for (int i = 0; i < multiPolygon.size(); i++) {
                drawPolygon(multiPolygon.get(i), display);
                drawText(scaledTextSize, center, display);
            }
            break;

        //throw new IllegalArgumentException(
        //        "The input geometry type is not support by this style");
    }
}
 
Example #2
Source File: SimplePolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void drawPolygon(GeoPolygon polygon, GISDisplay display) {
    float scaledWidth = (float) (mWidth / display.getScale());

    Paint lnPaint = new Paint();
    lnPaint.setColor(mOutColor);
    lnPaint.setStrokeWidth(scaledWidth);
    lnPaint.setStrokeCap(Paint.Cap.ROUND);
    lnPaint.setAntiAlias(true);

    Path polygonPath = getPath(polygon);

    lnPaint.setStyle(Paint.Style.STROKE);
    lnPaint.setAlpha(mOuterAlpha);
    display.drawPath(polygonPath, lnPaint);

    if (mFill) {
        lnPaint.setStyle(Paint.Style.FILL);
        lnPaint.setColor(mColor);
        lnPaint.setAlpha(mInnerAlpha);
        display.drawPath(polygonPath, lnPaint);
    }
}
 
Example #3
Source File: SimpleTiledPolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void drawPolygon(GeoPolygon polygon, GISDisplay display) {
    Paint lnPaint = new Paint();
    lnPaint.setColor(mColor);
    lnPaint.setStrokeWidth((float) (mWidth / display.getScale()));
    lnPaint.setStrokeCap(Paint.Cap.ROUND);
    lnPaint.setAntiAlias(true);

    Path polygonPath = getPath(polygon);

    lnPaint.setStyle(Paint.Style.STROKE);
    lnPaint.setAlpha(mOuterAlpha);
    display.drawPath(polygonPath, lnPaint);

    if (mFill) {
        lnPaint.setStyle(Paint.Style.FILL);
        lnPaint.setAlpha(mInnerAlpha);
        lnPaint.setStrokeWidth(0);
        display.drawPath(polygonPath, lnPaint);
    }
}
 
Example #4
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void fillDrawPolygon(GeoPolygon polygon) {
    mSelectedItem = new DrawItem();

    fillDrawRing(polygon.getOuterRing());
    for (int i = 0; i < polygon.getInnerRingCount(); i++)
        fillDrawRing(polygon.getInnerRing(i));

    mDrawItems.add(mSelectedItem);
}
 
Example #5
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setGeometryFromWalkEdit(GeoGeometry geometry) {
    int selectedGeometry = mDrawItems.indexOf(mSelectedItem);
    int selectedRing = mSelectedItem.getSelectedRingId();

    switch (mLayer.getGeometryType()) {
        case GeoConstants.GTLineString:
            mFeature.setGeometry(geometry);
            break;
        case GeoConstants.GTMultiLineString:
            GeoMultiLineString multiLine = (GeoMultiLineString) mFeature.getGeometry();
            multiLine.set(selectedGeometry, geometry);
            mFeature.setGeometry(multiLine);
            break;
        case GeoConstants.GTPolygon:
            GeoPolygon polygon = (GeoPolygon) mFeature.getGeometry();

            if (selectedRing == 0)
                polygon.setOuterRing((GeoLinearRing) geometry);
            else
                polygon.setInnerRing(selectedRing - 1, (GeoLinearRing) geometry);

            mFeature.setGeometry(polygon);
            break;
        case GeoConstants.GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) mFeature.getGeometry();
            GeoPolygon selectedPolygon = multiPolygon.get(selectedGeometry);
            selectedPolygon.setOuterRing((GeoLinearRing) geometry);

            if (selectedRing == 0)
                selectedPolygon.setOuterRing((GeoLinearRing) geometry);
            else
                selectedPolygon.setInnerRing(selectedRing - 1, (GeoLinearRing) geometry);

            multiPolygon.set(selectedGeometry, selectedPolygon);
            mFeature.setGeometry(multiPolygon);
            break;
    }
}
 
Example #6
Source File: SimplePolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Path getPath(GeoPolygon polygon) {
    List<GeoPoint> points = polygon.getOuterRing().getPoints();
    Path polygonPath = new Path();
    appendPath(polygonPath, points);

    for (int i = 0; i < polygon.getInnerRingCount(); i++) {
        points = polygon.getInnerRing(i).getPoints();
        appendPath(polygonPath, points);
    }

    polygonPath.setFillType(Path.FillType.EVEN_ODD);

    return polygonPath;
}
 
Example #7
Source File: SimpleTiledPolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onDraw(GeoGeometry geoGeometry, GISDisplay display) {
    switch (geoGeometry.getType()) {
        case GTPolygon:
            drawPolygon((GeoPolygon) geoGeometry, display);
            break;
        case GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) geoGeometry;

            for (int i = 0; i < multiPolygon.size(); i++) {
                drawPolygon(multiPolygon.get(i), display);
            }
            break;
        case GTPoint:
            drawPoint((GeoPoint) geoGeometry, display);
            break;
        case GTMultiPoint:
            GeoMultiPoint multiPoint = (GeoMultiPoint) geoGeometry;
            for (int i = 0; i < multiPoint.size(); i++) {
                drawPoint(multiPoint.get(i), display);
            }
            break;
        case GTLineString:
            drawLineString((GeoLineString) geoGeometry, display);
            break;
        case GTMultiLineString:
            GeoMultiLineString multiLineString = (GeoMultiLineString) geoGeometry;
            for (int i = 0; i < multiLineString.size(); i++) {
                drawLineString(multiLineString.get(i), display);
            }
            break;
    }
}
 
Example #8
Source File: SimpleTiledPolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Path getPath(GeoPolygon polygon) {
    List<GeoPoint> points = polygon.getOuterRing().getPoints();
    Path polygonPath = new Path();
    appendPath(polygonPath, points);

    for (int i = 0; i < polygon.getInnerRingCount(); i++) {
        points = polygon.getInnerRing(i).getPoints();
        appendPath(polygonPath, points);
    }

    polygonPath.setFillType(Path.FillType.EVEN_ODD);

    return polygonPath;
}
 
Example #9
Source File: MapUtil.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean isGeometryIntersects(Context context, GeoGeometry geometry) {
    if (geometry instanceof GeoPolygon) {
        if (((GeoPolygon) geometry).intersects()) {
            Toast.makeText(context, R.string.self_intersection, Toast.LENGTH_SHORT).show();
            return true;
        }

        if (!((GeoPolygon) geometry).isHolesInside()) {
            Toast.makeText(context, R.string.ring_outside, Toast.LENGTH_SHORT).show();
            return true;
        }

        if (((GeoPolygon) geometry).isHolesIntersect()) {
            Toast.makeText(context, R.string.rings_intersection, Toast.LENGTH_SHORT).show();
            return true;
        }
    }

    if (geometry instanceof GeoMultiPolygon) {
        if (((GeoMultiPolygon) geometry).isSelfIntersects()) {
            Toast.makeText(context, R.string.self_intersection, Toast.LENGTH_SHORT).show();
            return true;
        }

        if (!((GeoMultiPolygon) geometry).isHolesInside()) {
            Toast.makeText(context, R.string.ring_outside, Toast.LENGTH_SHORT).show();
            return true;
        }

        if (((GeoMultiPolygon) geometry).isHolesIntersect()) {
            Toast.makeText(context, R.string.rings_intersection, Toast.LENGTH_SHORT).show();
            return true;
        }
    }

    return false;
}
 
Example #10
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void startGeometryByWalk() {
    // register broadcast events
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WalkEditService.WALKEDIT_CHANGE);
    mReceiver = new WalkEditReceiver();
    mContext.registerReceiver(mReceiver, intentFilter);
    mHasEdits = true;

    if (WalkEditService.isServiceRunning(mContext))
        return;

    // start service if not started yet
    GeoGeometry geometry = mFeature.getGeometry();
    int selectedRing = mSelectedItem.getSelectedRingId();
    int selectedGeometry = mDrawItems.indexOf(mSelectedItem);

    switch (mLayer.getGeometryType()) {
        case GeoConstants.GTLineString:
            break;
        case GeoConstants.GTPolygon:
            GeoPolygon polygon = ((GeoPolygon) geometry);
            geometry = selectedRing == 0 ? polygon.getOuterRing() : polygon.getInnerRing(selectedRing - 1);
            break;
        case GeoConstants.GTMultiLineString:
            geometry = ((GeoMultiLineString) geometry).get(selectedGeometry);
            break;
        case GeoConstants.GTMultiPolygon:
            GeoPolygon selectedPolygon = ((GeoMultiPolygon) geometry).get(selectedGeometry);
            geometry = selectedRing == 0 ? selectedPolygon.getOuterRing() : selectedPolygon.getInnerRing(selectedRing - 1);
            break;
        default:
            return;
    }

    Intent trackerService = new Intent(mContext, WalkEditService.class);
    trackerService.setAction(WalkEditService.ACTION_START);
    trackerService.putExtra(ConstantsUI.KEY_LAYER_ID, mLayer.getId());
    trackerService.putExtra(ConstantsUI.KEY_GEOMETRY, geometry);
    trackerService.putExtra(ConstantsUI.TARGET_CLASS, mContext.getClass().getName());
    ContextCompat.startForegroundService(mContext, trackerService);
}
 
Example #11
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void fillDrawItems(GeoGeometry geom) {
    int lastItemsCount = mDrawItems.size();
    int lastSelectedItemPosition = mDrawItems.indexOf(mSelectedItem);
    DrawItem lastSelectedItem = mSelectedItem;
    mDrawItems.clear();

    if (null == geom) {
        Log.w(Constants.TAG, "the geometry is null in fillDrawItems method");
        return;
    }

    GeoPoint[] geoPoints = new GeoPoint[1];
    Location last = mGpsEventSource.getLastKnownLocation();
    switch (geom.getType()) {
        case GeoConstants.GTPoint:
            geoPoints[0] = (GeoPoint) geom;
            mSelectedItem = new DrawItem(DrawItem.TYPE_VERTEX, mapToScreen(geoPoints));
            mDrawItems.add(mSelectedItem);
            break;
        case GeoConstants.GTMultiPoint:
            GeoMultiPoint geoMultiPoint = (GeoMultiPoint) geom;
            for (int i = 0; i < geoMultiPoint.size(); i++) {
                geoPoints[0] = geoMultiPoint.get(i);
                mSelectedItem = new DrawItem(DrawItem.TYPE_VERTEX, mapToScreen(geoPoints));
                mDrawItems.add(mSelectedItem);
            }
            break;
        case GeoConstants.GTLineString:
            fillDrawLine((GeoLineString) geom);
            break;
        case GeoConstants.GTMultiLineString:
            GeoMultiLineString multiLineString = (GeoMultiLineString) geom;
            for (int i = 0; i < multiLineString.size(); i++)
                fillDrawLine(multiLineString.get(i));
            break;
        case GeoConstants.GTPolygon:
            fillDrawPolygon((GeoPolygon) geom);
            break;
        case GeoConstants.GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) geom;
            for (int i = 0; i < multiPolygon.size(); i++)
                fillDrawPolygon(multiPolygon.get(i));
            break;
        case GeoConstants.GTGeometryCollection:
            GeoGeometryCollection collection = (GeoGeometryCollection) geom;
            for (int i = 0; i < collection.size(); i++) {
                GeoGeometry geoGeometry = collection.get(i);
                fillDrawItems(geoGeometry);
            }
            break;
        default:
            break;
    }

    if (mDrawItems.size() == lastItemsCount && lastSelectedItem != null &&
            lastSelectedItemPosition != Constants.NOT_FOUND) {
        mSelectedItem = mDrawItems.get(lastSelectedItemPosition);
        mSelectedItem.setSelectedRing(lastSelectedItem.getSelectedRingId());
        mSelectedItem.setSelectedPoint(lastSelectedItem.getSelectedPointId());
    } else {
        mSelectedItem = mDrawItems.get(0);
    }

    switch (geom.getType()) {
        case GeoConstants.GTPoint:
        case GeoConstants.GTMultiPoint:
            updateDistance(last, null);
            break;
    }
}
 
Example #12
Source File: GeoUtil.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static GeoPolygon convexHull(List<GeoPoint> points){
    List<GeoPoint> sortedPoints = new ArrayList<>(points);
    Collections.sort(sortedPoints, new GeoPointsCompare());

    int n = sortedPoints.size();

    GeoPoint[] lUpper = new GeoPoint[n];

    lUpper[0] = sortedPoints.get(0);
    lUpper[1] = sortedPoints.get(1);

    int lUpperSize = 2;

    for (int i = 2; i < n; i++)
    {
        lUpper[lUpperSize] = sortedPoints.get(i);
        lUpperSize++;

        while (lUpperSize > 2 && !rightTurn(lUpper[lUpperSize - 3], lUpper[lUpperSize - 2], lUpper[lUpperSize - 1]))
        {
            // Remove the middle point of the three last
            lUpper[lUpperSize - 2] = lUpper[lUpperSize - 1];
            lUpperSize--;
        }
    }

    GeoPoint[] lLower = new GeoPoint[n];

    lLower[0] = sortedPoints.get(n - 1);
    lLower[1] = sortedPoints.get(n - 2);

    int lLowerSize = 2;

    for (int i = n - 3; i >= 0; i--)
    {
        lLower[lLowerSize] = sortedPoints.get(i);
        lLowerSize++;

        while (lLowerSize > 2 && !rightTurn(lLower[lLowerSize - 3], lLower[lLowerSize - 2], lLower[lLowerSize - 1]))
        {
            // Remove the middle point of the three last
            lLower[lLowerSize - 2] = lLower[lLowerSize - 1];
            lLowerSize--;
        }
    }

    GeoPolygon polygon = new GeoPolygon();
    for (int i = 0; i < lUpperSize; i++)
    {
        polygon.add(lUpper[i]);
    }

    for (int i = 1; i < lLowerSize - 1; i++)
    {
        polygon.add(lLower[i]);
    }

    return polygon;

}