Back to project page android_maplib.
The source code is released under:
GNU General Public License
If you think the Android project android_maplib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/****************************************************************************** * Project: NextGIS mobile// w w w . j a v a 2s . c o m * Purpose: Mobile GIS for Android. * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru ****************************************************************************** * Copyright (C) 2014 NextGIS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. ****************************************************************************/ package com.nextgis.maplib.datasource; import org.json.JSONArray; import org.json.JSONException; import static com.nextgis.maplib.util.GeoConstants.GTPolygon; public class GeoPolygon extends GeoGeometry { protected GeoLinearRing mOuterRing; public GeoPolygon() { mOuterRing = new GeoLinearRing(); } public void add(GeoPoint point) { mOuterRing.add(point); } public GeoPoint remove(int index) { return mOuterRing.remove(index); } @Override protected boolean rawProject(int toCrs) { return mOuterRing.rawProject(toCrs); } @Override public GeoEnvelope getEnvelope() { return mOuterRing.getEnvelope(); } @Override public JSONArray coordinatesToJSON() throws JSONException { JSONArray coordinates = new JSONArray(); coordinates.put(mOuterRing.coordinatesToJSON()); return coordinates; } @Override public int getType() { return GTPolygon; } @Override public void setCoordinatesFromJSON(JSONArray coordinates) throws JSONException { JSONArray outerRingCoordinates = coordinates.getJSONArray(0); if (outerRingCoordinates.length() < 4) { throw new JSONException( "For type \"Polygon\", the \"coordinates\" member must be an array of LinearRing coordinate arrays. A LinearRing must be with 4 or more positions."); } mOuterRing.setCoordinatesFromJSON(outerRingCoordinates); if (!getOuterRing().isClosed()) { throw new JSONException( "For type \"Polygon\", the \"coordinates\" member must be an array of LinearRing coordinate arrays. The first and last positions of LinearRing must be equivalent (they represent equivalent points)."); } } public GeoLinearRing getOuterRing() { return mOuterRing; } }