├── .gitignore ├── LICENSE.md ├── README.md ├── androidgeojson ├── build.gradle ├── gradle.properties └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── cocoahero │ └── android │ └── geojson │ ├── Feature.java │ ├── FeatureCollection.java │ ├── GeoJSON.java │ ├── GeoJSONObject.java │ ├── Geometry.java │ ├── GeometryCollection.java │ ├── LineString.java │ ├── MultiLineString.java │ ├── MultiPoint.java │ ├── MultiPolygon.java │ ├── Point.java │ ├── Polygon.java │ ├── Position.java │ ├── PositionList.java │ ├── Ring.java │ └── util │ ├── JSONUtils.java │ ├── ListUtils.java │ └── StreamUtils.java ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── project.properties └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built Application Files 2 | *.apk 3 | *.ap_ 4 | 5 | # Dex VM 6 | *.dex 7 | 8 | # Java Class Files 9 | *.class 10 | 11 | # Generated Files 12 | bin/ 13 | gen/ 14 | 15 | # Mac OS X 16 | .DS_Store 17 | *.tmp 18 | *.bak 19 | *.swp 20 | 21 | # Eclipse 22 | tmp/** 23 | .classpath 24 | .project 25 | .settings 26 | 27 | # Ant Local Configuration 28 | local.properties 29 | 30 | # Android Studio 31 | *.iml 32 | .idea/ 33 | .gradle/ 34 | build/ 35 | 36 | *.keystore 37 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jonathan Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android GeoJSON 2 | 3 | A complete GeoJSON implementation for Android. 4 | 5 | ### Table of Contents 6 | 7 | * [Requirements](#requirements) 8 | * [Installation](#installation) 9 | * [Sample Usage](#sample-usage) 10 | * [Parsing GeoJSON](#parsing-geojson) 11 | * [Creating GeoJSON](#creating-geojson) 12 | 13 | ### Requirements 14 | * Android SDK 8 or Higher 15 | 16 | ### Installation 17 | 18 | #### Android Studio / Gradle 19 | 20 | ````groovy 21 | dependencies { 22 | compile 'com.cocoahero.android:geojson:1.0.1@jar' 23 | } 24 | ```` 25 | 26 | #### Maven 27 | 28 | ````xml 29 | 30 | com.cocoahero.android 31 | geojson 32 | 1.0.1 33 | jar 34 | 35 | ```` 36 | 37 | ### Sample Usage 38 | 39 | Whether you need to parse existing GeoJSON from a file or web server, or create new GeoJSON from user input, this library has got you covered. 40 | 41 | #### Parsing GeoJSON 42 | 43 | If you have existing GeoJSON that you need to parse, you have three source options with this library: 44 | 45 | 1. String 46 | 2. JSONObject 47 | 3. InputStream 48 | 49 | Once you have your GeoJSON in one of the above formats, simply pass it to `GeoJSON#parse`. 50 | 51 | ##### String 52 | ````java 53 | String string; // A string containing GeoJSON 54 | 55 | try { 56 | GeoJSONObject geoJSON = GeoJSON.parse(string); 57 | } 58 | catch (JSONException e) { 59 | e.printStackTrace(); 60 | } 61 | ```` 62 | 63 | ##### JSONObject 64 | ````java 65 | JSONObject json; // A JSONObject formatted as GeoJSON 66 | 67 | GeoJSONObject geoJSON = GeoJSON.parse(json); 68 | ```` 69 | 70 | ##### InputStream 71 | ````java 72 | InputStream stream; // An InputStream pointing to GeoJSON 73 | 74 | try { 75 | GeoJSONObject geoJSON = GeoJSON.parse(stream); 76 | } 77 | catch (IOException e) { 78 | e.printStackTrace(); 79 | } 80 | catch (JSONException e) { 81 | e.printStackTrace(); 82 | } 83 | ```` 84 | 85 | The returned object instance will be a subclass of [GeoJSONObject](./androidgeojson/src/main/java/com/cocoahero/android/geojson/GeoJSONObject.java), depending on the `type` property of the GeoJSON. 86 | 87 | * `"type": "Feature"` => [Feature](./androidgeojson/src/main/java/com/cocoahero/android/geojson/Feature.java) 88 | * `"type": "FeatureCollection"` => [FeatureCollection](./androidgeojson/src/main/java/com/cocoahero/android/geojson/FeatureCollection.java) 89 | * `"type": "Point"` => [Point](./androidgeojson/src/main/java/com/cocoahero/android/geojson/Point.java) 90 | * `"type": "MultiPoint"` => [MultiPoint](./androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiPoint.java) 91 | * `"type": "LineString"` => [LineString](./androidgeojson/src/main/java/com/cocoahero/android/geojson/LineString.java) 92 | * `"type": "MultiLineString"` => [MultiLineString](./androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiLineString.java) 93 | * `"type": "Polygon"` => [Polygon](./androidgeojson/src/main/java/com/cocoahero/android/geojson/Polygon.java) 94 | * `"type": "MultiPolygon"` => [MultiPolygon](./androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiPolygon.java) 95 | * `"type": "GeometryCollection"` => [GeometryCollection](./androidgeojson/src/main/java/com/cocoahero/android/geojson/GeometryCollection.java) 96 | 97 | #### Creating GeoJSON 98 | 99 | Parsing existing GeoJSON is only half the fun! Why not create new GeoJSON?! Simply create a new instance of which ever GeoJSONObject sub-type you would like, then call `#toJSON` on it to get a properly formatted `JSONObject` instance. 100 | 101 | For example, the following sample code creates a GeoJSON Feature with a Point geometry. 102 | 103 | ````java 104 | // Create geometry 105 | Point point = new Point(38.889462878011365, -77.03525304794312); 106 | 107 | // Create feature with geometry 108 | Feature feature = new Feature(point); 109 | 110 | // Set optional feature identifier 111 | feature.setIdentifier("MyIdentifier"); 112 | 113 | // Set optional feature properties 114 | feature.setProperties(new JSONObject()); 115 | 116 | // Convert to formatted JSONObject 117 | JSONObject geoJSON = feature.toJSON(); 118 | ```` 119 | 120 | The resulting GeoJSON can be seen [here](https://gist.github.com/cocoahero/7ce6bc203d47d7a64438#file-sample-feature-geojson). 121 | -------------------------------------------------------------------------------- /androidgeojson/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven' 2 | apply plugin: 'signing' 3 | apply plugin: 'com.android.library' 4 | 5 | android { 6 | defaultConfig { 7 | minSdkVersion 8 8 | targetSdkVersion 22 9 | versionName VERSION_NAME 10 | versionCode getBuildNumber() 11 | } 12 | 13 | compileSdkVersion 22 14 | buildToolsVersion "21.1.2" 15 | } 16 | 17 | def isReleaseBuild() { 18 | return VERSION_NAME.contains("SNAPSHOT") == false 19 | } 20 | 21 | def getBuildNumber() { 22 | return "git log --pretty=format:''".execute().text.readLines().size() 23 | } 24 | 25 | def getReleaseRepositoryUrl() { 26 | return "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 27 | } 28 | 29 | def getSnapshotRepositoryUrl() { 30 | return "https://oss.sonatype.org/content/repositories/snapshots/" 31 | } 32 | 33 | def getRepositoryUsername() { 34 | return hasProperty('USERNAME') ? USERNAME : 35 | (hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "") 36 | } 37 | 38 | def getRepositoryPassword() { 39 | return hasProperty('PASSWORD') ? PASSWORD : 40 | (hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "") 41 | } 42 | 43 | android.libraryVariants.all { variant -> 44 | def jarTask = project.tasks.create(name: "jar${variant.name.capitalize()}", type: Jar) { 45 | from variant.javaCompile.destinationDir 46 | exclude "**/R.class" 47 | exclude "**/BuildConfig.class" 48 | } 49 | jarTask.dependsOn variant.javaCompile 50 | artifacts.add('archives', jarTask); 51 | } 52 | 53 | task androidJavadocs(type: Javadoc) { 54 | source = android.sourceSets.main.java.sourceFiles 55 | classpath += project.files(android.bootClasspath.join(File.pathSeparator)) 56 | options.linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference" 57 | exclude '**/R.html', '**/R.*.html' 58 | } 59 | 60 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 61 | classifier = 'javadoc' 62 | from androidJavadocs.destinationDir 63 | } 64 | 65 | task androidSourcesJar(type: Jar) { 66 | classifier = 'sources' 67 | from android.sourceSets.main.java.sourceFiles 68 | } 69 | 70 | artifacts { 71 | archives androidSourcesJar 72 | archives androidJavadocsJar 73 | } 74 | 75 | afterEvaluate { project -> 76 | uploadArchives { 77 | repositories { 78 | mavenDeployer { 79 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 80 | 81 | pom.groupId = POM_GROUP_ID 82 | pom.artifactId = POM_ARTIFACT_ID 83 | pom.version = VERSION_NAME 84 | 85 | repository(url: getReleaseRepositoryUrl()) { 86 | authentication(userName: getRepositoryUsername(), 87 | password: getRepositoryPassword()) 88 | } 89 | 90 | snapshotRepository(url: getSnapshotRepositoryUrl()) { 91 | authentication(userName: getRepositoryUsername(), 92 | password: getRepositoryPassword()) 93 | } 94 | 95 | pom.project { 96 | name POM_NAME 97 | packaging POM_PACKAGING 98 | description POM_DESCRIPTION 99 | url POM_URL 100 | 101 | scm { 102 | url POM_SCM_URL 103 | connection POM_SCM_CONNECTION 104 | developerConnection POM_SCM_DEV_CONNECTION 105 | } 106 | 107 | licenses { 108 | license { 109 | name POM_LICENCE_NAME 110 | url POM_LICENCE_URL 111 | distribution POM_LICENCE_DIST 112 | } 113 | } 114 | 115 | developers { 116 | developer { 117 | id POM_DEVELOPER_ID 118 | name POM_DEVELOPER_NAME 119 | } 120 | } 121 | } 122 | } 123 | } 124 | } 125 | 126 | signing { 127 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 128 | sign configurations.archives 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /androidgeojson/gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=1.0.1 2 | 3 | POM_NAME=Android GeoJSON Library 4 | POM_DESCRIPTION=Android GeoJSON Library 5 | POM_URL=https://github.com/cocoahero/android-geojson 6 | POM_SCM_URL=https://github.com/cocoahero/android-geojson 7 | POM_SCM_CONNECTION=scm:git:git@github.com:cocoahero/android-geojson 8 | POM_SCM_DEV_CONNECTION=scm:git:git@github.com:cocoahero/android-geojson 9 | POM_LICENCE_NAME=The MIT License 10 | POM_LICENCE_URL=https://github.com/cocoahero/android-geojson/blob/master/LICENSE.md 11 | POM_LICENCE_DIST=repo 12 | POM_PACKAGING=aar 13 | 14 | POM_ARTIFACT_ID=geojson 15 | POM_GROUP_ID=com.cocoahero.android 16 | 17 | POM_DEVELOPER_ID=cocoahero 18 | POM_DEVELOPER_NAME=Jonathan Baker 19 | -------------------------------------------------------------------------------- /androidgeojson/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/Feature.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.cocoahero.android.geojson.util.JSONUtils; 7 | 8 | import org.json.JSONException; 9 | import org.json.JSONObject; 10 | 11 | public class Feature extends GeoJSONObject { 12 | 13 | // ------------------------------------------------------------------------ 14 | // Private Constants 15 | // ------------------------------------------------------------------------ 16 | 17 | private static final String JSON_ID = "id"; 18 | 19 | private static final String JSON_GEOMETRY = "geometry"; 20 | 21 | private static final String JSON_PROPERTIES = "properties"; 22 | 23 | // ------------------------------------------------------------------------ 24 | // Instance Variables 25 | // ------------------------------------------------------------------------ 26 | 27 | private String mIdentifier; 28 | 29 | private Geometry mGeometry; 30 | 31 | private JSONObject mProperties; 32 | 33 | // ------------------------------------------------------------------------ 34 | // Constructors 35 | // ------------------------------------------------------------------------ 36 | 37 | /** 38 | * Creates an empty Feature without a geometry. 39 | */ 40 | public Feature() { 41 | // Default Constructor 42 | } 43 | 44 | /** 45 | * Parses the given {@link JSONObject} as a GeoJSON Feature. 46 | * 47 | * @param json 48 | */ 49 | public Feature(JSONObject json) { 50 | super(json); 51 | 52 | this.mIdentifier = JSONUtils.optString(json, JSON_ID); 53 | 54 | JSONObject geometry = json.optJSONObject(JSON_GEOMETRY); 55 | if (geometry != null) { 56 | this.mGeometry = (Geometry) GeoJSON.parse(geometry); 57 | } 58 | 59 | this.mProperties = json.optJSONObject(JSON_PROPERTIES); 60 | } 61 | 62 | /** 63 | * Creates a new GeoJSON Feature object with the given geometry. 64 | * 65 | * @param geometry 66 | */ 67 | public Feature(Geometry geometry) { 68 | this.mGeometry = geometry; 69 | } 70 | 71 | // ------------------------------------------------------------------------ 72 | // Parcelable Interface 73 | // ------------------------------------------------------------------------ 74 | 75 | public static final Parcelable.Creator CREATOR = new Creator() { 76 | @Override 77 | public Feature createFromParcel(Parcel in) { 78 | return (Feature) readParcel(in); 79 | } 80 | 81 | @Override 82 | public Feature[] newArray(int size) { 83 | return new Feature[size]; 84 | } 85 | }; 86 | 87 | // ------------------------------------------------------------------------ 88 | // Public Methods 89 | // ------------------------------------------------------------------------ 90 | 91 | /** 92 | * The optional, common identifier of this feature. 93 | * 94 | * @return The common identifier of this feature, if set. 95 | */ 96 | public String getIdentifier() { 97 | return this.mIdentifier; 98 | } 99 | 100 | /** 101 | * Sets the optional, common identifier of this feature. 102 | * 103 | * @param identifier 104 | */ 105 | public void setIdentifier(String identifier) { 106 | this.mIdentifier = identifier; 107 | } 108 | 109 | /** 110 | * Returns the geometry of this feature. It will be a concrete instance of 111 | * {@link Geometry}. 112 | * 113 | * @return the geometry of this feature, or null if not set. 114 | */ 115 | public Geometry getGeometry() { 116 | return this.mGeometry; 117 | } 118 | 119 | /** 120 | * Sets the {@link Geometry} of this feature. 121 | * 122 | * @param geometry 123 | */ 124 | public void setGeometry(Geometry geometry) { 125 | this.mGeometry = geometry; 126 | } 127 | 128 | /** 129 | * Returns the optional properties of this feature as JSON. 130 | * 131 | * @return the properties of this feature 132 | */ 133 | public JSONObject getProperties() { 134 | return this.mProperties; 135 | } 136 | 137 | /** 138 | * Sets the properties of this feature. 139 | * 140 | * @param properties 141 | */ 142 | public void setProperties(JSONObject properties) { 143 | this.mProperties = properties; 144 | } 145 | 146 | /** 147 | * {@inheritDoc} 148 | */ 149 | @Override 150 | public String getType() { 151 | return GeoJSON.TYPE_FEATURE; 152 | } 153 | 154 | /** 155 | * {@inheritDoc} 156 | */ 157 | @Override 158 | public JSONObject toJSON() throws JSONException { 159 | JSONObject json = super.toJSON(); 160 | 161 | json.put(JSON_ID, this.mIdentifier); 162 | 163 | if (this.mGeometry != null) { 164 | json.put(JSON_GEOMETRY, this.mGeometry.toJSON()); 165 | } else { 166 | json.put(JSON_GEOMETRY, JSONObject.NULL); 167 | } 168 | 169 | if (this.mProperties != null) { 170 | json.put(JSON_PROPERTIES, this.mProperties); 171 | } else { 172 | json.put(JSON_PROPERTIES, JSONObject.NULL); 173 | } 174 | 175 | return json; 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/FeatureCollection.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import org.json.JSONArray; 7 | import org.json.JSONException; 8 | import org.json.JSONObject; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class FeatureCollection extends GeoJSONObject { 14 | 15 | // ------------------------------------------------------------------------ 16 | // Constants 17 | // ------------------------------------------------------------------------ 18 | 19 | public static final String JSON_FEATURES = "features"; 20 | 21 | // ------------------------------------------------------------------------ 22 | // Instance Variables 23 | // ------------------------------------------------------------------------ 24 | 25 | private final List mFeatures = new ArrayList(); 26 | 27 | // ------------------------------------------------------------------------ 28 | // Constructors 29 | // ------------------------------------------------------------------------ 30 | 31 | /** 32 | * Creates an empty feature collection. 33 | */ 34 | public FeatureCollection() { 35 | // Default Constructor 36 | } 37 | 38 | /** 39 | * Parses the given {@link JSONObject} as a feature collection. 40 | * 41 | * @param json 42 | */ 43 | public FeatureCollection(JSONObject json) { 44 | super(json); 45 | 46 | JSONArray features = json.optJSONArray(JSON_FEATURES); 47 | if (features != null) { 48 | for (int i = 0; i < features.length(); i++) { 49 | JSONObject featureJSON = features.optJSONObject(i); 50 | if (featureJSON != null) { 51 | this.mFeatures.add(new Feature(featureJSON)); 52 | } 53 | } 54 | } 55 | } 56 | 57 | // ------------------------------------------------------------------------ 58 | // Parcelable Interface 59 | // ------------------------------------------------------------------------ 60 | 61 | public static final Parcelable.Creator CREATOR = new Creator() { 62 | @Override 63 | public FeatureCollection createFromParcel(Parcel in) { 64 | return (FeatureCollection) readParcel(in); 65 | } 66 | 67 | @Override 68 | public FeatureCollection[] newArray(int size) { 69 | return new FeatureCollection[size]; 70 | } 71 | }; 72 | 73 | // ------------------------------------------------------------------------ 74 | // Public Methods 75 | // ------------------------------------------------------------------------ 76 | 77 | /** 78 | * Adds a {@link Feature} to this feature collection. 79 | * 80 | * @param feature 81 | */ 82 | public void addFeature(Feature feature) { 83 | this.mFeatures.add(feature); 84 | } 85 | 86 | /** 87 | * Removes a given {@link Feature} from this feature collection. 88 | * 89 | * @param feature 90 | */ 91 | public void removeFeature(Feature feature) { 92 | this.mFeatures.remove(feature); 93 | } 94 | 95 | /** 96 | * Returns a list of all the {@link Feature}s contained within this 97 | * collection. 98 | * 99 | * @return the list of all {@link Feature}s in this collection 100 | */ 101 | public List getFeatures() { 102 | return this.mFeatures; 103 | } 104 | 105 | /** 106 | * Sets the list of features contained within this feature collection. All 107 | * previously existing features are removed as a result of setting this 108 | * property. 109 | * 110 | * @param features 111 | */ 112 | public void setFeatures(List features) { 113 | this.mFeatures.clear(); 114 | if (features != null) { 115 | this.mFeatures.addAll(features); 116 | } 117 | } 118 | 119 | /** 120 | * {@inheritDoc} 121 | */ 122 | @Override 123 | public String getType() { 124 | return GeoJSON.TYPE_FEATURE_COLLECTION; 125 | } 126 | 127 | /** 128 | * {@inheritDoc} 129 | */ 130 | @Override 131 | public JSONObject toJSON() throws JSONException { 132 | JSONObject json = super.toJSON(); 133 | 134 | JSONArray features = new JSONArray(); 135 | for (Feature feature : this.mFeatures) { 136 | features.put(feature.toJSON()); 137 | } 138 | 139 | json.put(JSON_FEATURES, features); 140 | 141 | return json; 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/GeoJSON.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import com.cocoahero.android.geojson.util.JSONUtils; 4 | import com.cocoahero.android.geojson.util.StreamUtils; 5 | 6 | import org.json.JSONException; 7 | import org.json.JSONObject; 8 | 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | 12 | public class GeoJSON { 13 | 14 | // ------------------------------------------------------------------------ 15 | // Public Constants 16 | // ------------------------------------------------------------------------ 17 | 18 | public static final String TYPE_POINT = "Point"; 19 | 20 | public static final String TYPE_MULTI_POINT = "MultiPoint"; 21 | 22 | public static final String TYPE_LINE_STRING = "LineString"; 23 | 24 | public static final String TYPE_MULTI_LINE_STRING = "MultiLineString"; 25 | 26 | public static final String TYPE_POLYGON = "Polygon"; 27 | 28 | public static final String TYPE_MULTI_POLYGON = "MultiPolygon"; 29 | 30 | public static final String TYPE_GEOMETRY_COLLECTION = "GeometryCollection"; 31 | 32 | public static final String TYPE_FEATURE = "Feature"; 33 | 34 | public static final String TYPE_FEATURE_COLLECTION = "FeatureCollection"; 35 | 36 | // ------------------------------------------------------------------------ 37 | // Class Methods 38 | // ------------------------------------------------------------------------ 39 | 40 | /** 41 | * Parses the given JSONObject as GeoJSON and returns a concrete subclass of 42 | * {@link GeoJSONObject} corresponding to the type of the root object. 43 | *

44 | * Example: 45 | *

 46 |      * {
 47 |      *     "type": "Feature",
 48 |      *     "geometry": {
 49 |      *         "type": "Point",
 50 |      *         "coordinates": [125.6, 10.1]
 51 |      *     },
 52 |      * }
 53 |      * 
54 | *

55 | * The above GeoJSON would return an instance of {@link Feature}. 56 | * 57 | * @param json 58 | * A {@link JSONObject} to parse as GeoJSON 59 | * 60 | * @return A concrete subclass instance of {@link GeoJSONObject}. 61 | * 62 | * @throws IllegalArgumentException 63 | * If the given object is not a valid GeoJSON type. 64 | */ 65 | public static GeoJSONObject parse(JSONObject json) { 66 | String type = JSONUtils.optString(json, GeoJSONObject.JSON_TYPE); 67 | 68 | if (TYPE_POINT.equalsIgnoreCase(type)) { 69 | return new Point(json); 70 | } 71 | 72 | if (TYPE_MULTI_POINT.equalsIgnoreCase(type)) { 73 | return new MultiPoint(json); 74 | } 75 | 76 | if (TYPE_LINE_STRING.equalsIgnoreCase(type)) { 77 | return new LineString(json); 78 | } 79 | 80 | if (TYPE_MULTI_LINE_STRING.equalsIgnoreCase(type)) { 81 | return new MultiLineString(json); 82 | } 83 | 84 | if (TYPE_POLYGON.equalsIgnoreCase(type)) { 85 | return new Polygon(json); 86 | } 87 | 88 | if (TYPE_MULTI_POLYGON.equalsIgnoreCase(type)) { 89 | return new MultiPolygon(json); 90 | } 91 | 92 | if (TYPE_GEOMETRY_COLLECTION.equalsIgnoreCase(type)) { 93 | return new GeometryCollection(json); 94 | } 95 | 96 | if (TYPE_FEATURE.equalsIgnoreCase(type)) { 97 | return new Feature(json); 98 | } 99 | 100 | if (TYPE_FEATURE_COLLECTION.equalsIgnoreCase(type)) { 101 | return new FeatureCollection(json); 102 | } 103 | 104 | throw new IllegalArgumentException("The type '" + type + "' is not a valid GeoJSON type."); 105 | } 106 | 107 | /** 108 | * Parses the given {@link String} into a {@link JSONObject}, and then 109 | * passes it to {@link GeoJSON#parse(JSONObject)}. 110 | * 111 | * @param jsonString 112 | * A {@link String} to parse as GeoJSON 113 | * 114 | * @return A concrete subclass instance of {@link GeoJSONObject}. 115 | * 116 | * @throws JSONException 117 | */ 118 | public static GeoJSONObject parse(String jsonString) throws JSONException { 119 | return parse(new JSONObject(jsonString)); 120 | } 121 | 122 | /** 123 | * Parses the given {@link InputStream} into a {@link JSONObject}, and then 124 | * passes it to {@link GeoJSON#parse(JSONObject)}. 125 | * 126 | * @param stream 127 | * An {@link InputStream} to parse as GeoJSON 128 | * 129 | * @return A concrete subclass instance of {@link GeoJSONObject}. 130 | * 131 | * @throws IOException 132 | * @throws JSONException 133 | */ 134 | public static GeoJSONObject parse(InputStream stream) throws IOException, JSONException { 135 | return parse(StreamUtils.toString(stream)); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/GeoJSONObject.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import org.json.JSONException; 7 | import org.json.JSONObject; 8 | 9 | /** 10 | * The abstract interface of all GeoJSON objects. 11 | */ 12 | public abstract class GeoJSONObject implements Parcelable { 13 | 14 | // ------------------------------------------------------------------------ 15 | // Public Constants 16 | // ------------------------------------------------------------------------ 17 | 18 | public static final String JSON_TYPE = "type"; 19 | 20 | // ------------------------------------------------------------------------ 21 | // Class Methods 22 | // ------------------------------------------------------------------------ 23 | 24 | protected static GeoJSONObject readParcel(Parcel parcel) { 25 | String json = parcel.readString(); 26 | try { 27 | return GeoJSON.parse(json); 28 | } 29 | catch (JSONException e) { 30 | throw new RuntimeException(e); 31 | } 32 | } 33 | 34 | // ------------------------------------------------------------------------ 35 | // Constructor 36 | // ------------------------------------------------------------------------ 37 | 38 | public GeoJSONObject() { 39 | // Default Constructor 40 | } 41 | 42 | public GeoJSONObject(JSONObject json) { 43 | 44 | } 45 | 46 | // ------------------------------------------------------------------------ 47 | // Parcelable Interface 48 | // ------------------------------------------------------------------------ 49 | 50 | public static final Parcelable.Creator CREATOR = new Creator() { 51 | @Override 52 | public GeoJSONObject createFromParcel(Parcel in) { 53 | return readParcel(in); 54 | } 55 | 56 | @Override 57 | public GeoJSONObject[] newArray(int size) { 58 | return new GeoJSONObject[size]; 59 | } 60 | }; 61 | 62 | @Override 63 | public int describeContents() { 64 | return 0; 65 | } 66 | 67 | @Override 68 | public void writeToParcel(Parcel dest, int flags) { 69 | try { 70 | dest.writeString(this.toJSON().toString()); 71 | } 72 | catch (JSONException e) { 73 | throw new RuntimeException(e); 74 | } 75 | } 76 | 77 | // ------------------------------------------------------------------------ 78 | // Public Methods 79 | // ------------------------------------------------------------------------ 80 | 81 | /** 82 | * The type of GeoJSON object. This will be one of the constants defined in 83 | * {@link GeoJSON}, such as {@link GeoJSON#TYPE_FEATURE}. 84 | * 85 | * @return The type of GeoJSON object. 86 | */ 87 | public abstract String getType(); 88 | 89 | /** 90 | * Formats the object's attributes as GeoJSON. 91 | * 92 | * @return A GeoJSON formatted {@link JSONObject} 93 | * 94 | * @throws JSONException 95 | */ 96 | public JSONObject toJSON() throws JSONException { 97 | JSONObject json = new JSONObject(); 98 | 99 | json.put(JSON_TYPE, this.getType()); 100 | 101 | return json; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/Geometry.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONException; 5 | import org.json.JSONObject; 6 | 7 | /** 8 | * An intermediate, abstract class that acts as a common base for all GeoJSON 9 | * geometry types. 10 | */ 11 | public abstract class Geometry extends GeoJSONObject { 12 | 13 | // ------------------------------------------------------------------------ 14 | // Public Constants 15 | // ------------------------------------------------------------------------ 16 | 17 | public static final String JSON_COORDINATES = "coordinates"; 18 | 19 | // ------------------------------------------------------------------------ 20 | // Constructors 21 | // ------------------------------------------------------------------------ 22 | 23 | public Geometry() { 24 | // Default Constructor 25 | } 26 | 27 | public Geometry(JSONObject json) { 28 | super(json); 29 | } 30 | 31 | // ------------------------------------------------------------------------ 32 | // Public Methods 33 | // ------------------------------------------------------------------------ 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public JSONObject toJSON() throws JSONException { 40 | JSONObject json = super.toJSON(); 41 | 42 | json.put(JSON_COORDINATES, new JSONArray()); 43 | 44 | return json; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/GeometryCollection.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import org.json.JSONArray; 7 | import org.json.JSONException; 8 | import org.json.JSONObject; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class GeometryCollection extends Geometry { 14 | 15 | // ------------------------------------------------------------------------ 16 | // Public Constants 17 | // ------------------------------------------------------------------------ 18 | 19 | public static final String JSON_GEOMETRIES = "geometries"; 20 | 21 | // ------------------------------------------------------------------------ 22 | // Instance Variables 23 | // ------------------------------------------------------------------------ 24 | 25 | private final List mGeometries = new ArrayList(); 26 | 27 | // ------------------------------------------------------------------------ 28 | // Constructors 29 | // ------------------------------------------------------------------------ 30 | 31 | /** 32 | * Creates an empty geometry collection. 33 | */ 34 | public GeometryCollection() { 35 | // Default Constructor 36 | } 37 | 38 | /** 39 | * Parses the given {@link JSONObject} as a geometry collection. 40 | * 41 | * @param json 42 | */ 43 | public GeometryCollection(JSONObject json) { 44 | super(json); 45 | 46 | JSONArray geometries = json.optJSONArray(JSON_GEOMETRIES); 47 | if (geometries != null) { 48 | for (int i = 0; i < geometries.length(); i++) { 49 | JSONObject geometry = geometries.optJSONObject(i); 50 | if (geometry != null) { 51 | this.mGeometries.add((Geometry) GeoJSON.parse(geometry)); 52 | } 53 | } 54 | } 55 | } 56 | 57 | // ------------------------------------------------------------------------ 58 | // Parcelable Interface 59 | // ------------------------------------------------------------------------ 60 | 61 | public static final Parcelable.Creator CREATOR = new Creator() { 62 | @Override 63 | public GeometryCollection createFromParcel(Parcel in) { 64 | return (GeometryCollection) readParcel(in); 65 | } 66 | 67 | @Override 68 | public GeometryCollection[] newArray(int size) { 69 | return new GeometryCollection[size]; 70 | } 71 | }; 72 | 73 | // ------------------------------------------------------------------------ 74 | // Public Methods 75 | // ------------------------------------------------------------------------ 76 | 77 | /** 78 | * Adds a {@link Geometry} to this geometry collection. 79 | * 80 | * @param geometry 81 | */ 82 | public void addGeometry(Geometry geometry) { 83 | this.mGeometries.add(geometry); 84 | } 85 | 86 | /** 87 | * Removes the given {@link Geometry} from this geometry collection. 88 | * 89 | * @param geometry 90 | */ 91 | public void removeGeometry(Geometry geometry) { 92 | this.mGeometries.remove(geometry); 93 | } 94 | 95 | /** 96 | * Returns a list of all the {@link Geometry} contained within this geometry 97 | * collection. 98 | * 99 | * @return a list of all the {@link Geometry} in this geometry collection. 100 | */ 101 | public List getGeometries() { 102 | return this.mGeometries; 103 | } 104 | 105 | /** 106 | * Sets the list of geometries contained within this geometry collection. 107 | * All previously existing geometries are removed as a result of setting 108 | * this property. 109 | * 110 | * @param geometries 111 | */ 112 | public void setGeometries(List geometries) { 113 | this.mGeometries.clear(); 114 | if (geometries != null) { 115 | this.mGeometries.addAll(geometries); 116 | } 117 | } 118 | 119 | /** 120 | * {@inheritDoc} 121 | */ 122 | @Override 123 | public String getType() { 124 | return GeoJSON.TYPE_GEOMETRY_COLLECTION; 125 | } 126 | 127 | /** 128 | * {@inheritDoc} 129 | */ 130 | @Override 131 | public JSONObject toJSON() throws JSONException { 132 | JSONObject json = super.toJSON(); 133 | 134 | JSONArray geometries = new JSONArray(); 135 | for (Geometry geometry : this.mGeometries) { 136 | geometries.put(geometry.toJSON()); 137 | } 138 | 139 | json.put(JSON_GEOMETRIES, geometries); 140 | 141 | return json; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/LineString.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import java.util.List; 4 | 5 | import org.json.JSONArray; 6 | import org.json.JSONException; 7 | import org.json.JSONObject; 8 | 9 | import android.os.Parcel; 10 | import android.os.Parcelable; 11 | 12 | public class LineString extends Geometry { 13 | 14 | // ------------------------------------------------------------------------ 15 | // Instance Variables 16 | // ------------------------------------------------------------------------ 17 | 18 | private final PositionList mPositionList = new PositionList(); 19 | 20 | // ------------------------------------------------------------------------ 21 | // Constructors 22 | // ------------------------------------------------------------------------ 23 | 24 | public LineString() { 25 | // Default Constructor 26 | } 27 | 28 | public LineString(JSONObject json) { 29 | super(json); 30 | 31 | this.setPositions(json.optJSONArray(JSON_COORDINATES)); 32 | } 33 | 34 | public LineString(JSONArray positions) { 35 | this.setPositions(positions); 36 | } 37 | 38 | // ------------------------------------------------------------------------ 39 | // Parcelable Interface 40 | // ------------------------------------------------------------------------ 41 | 42 | public static final Parcelable.Creator CREATOR = new Creator() { 43 | @Override 44 | public LineString createFromParcel(Parcel in) { 45 | return (LineString) readParcel(in); 46 | } 47 | 48 | @Override 49 | public LineString[] newArray(int size) { 50 | return new LineString[size]; 51 | } 52 | }; 53 | 54 | // ------------------------------------------------------------------------ 55 | // Public Methods 56 | // ------------------------------------------------------------------------ 57 | 58 | public void addPosition(Position position) { 59 | this.mPositionList.addPosition(position); 60 | } 61 | 62 | public void removePosition(Position position) { 63 | this.mPositionList.removePosition(position); 64 | } 65 | 66 | public List getPositions() { 67 | return this.mPositionList.getPositions(); 68 | } 69 | 70 | public void setPositions(JSONArray positions) { 71 | this.mPositionList.setPositions(positions); 72 | } 73 | 74 | public void setPositions(List positions) { 75 | this.mPositionList.setPositions(positions); 76 | } 77 | 78 | public boolean isLinearRing() { 79 | return this.mPositionList.isLinearRing(); 80 | } 81 | 82 | @Override 83 | public String getType() { 84 | return GeoJSON.TYPE_LINE_STRING; 85 | } 86 | 87 | @Override 88 | public JSONObject toJSON() throws JSONException { 89 | JSONObject json = super.toJSON(); 90 | 91 | json.put(JSON_COORDINATES, this.mPositionList.toJSON()); 92 | 93 | return json; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiLineString.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.json.JSONArray; 7 | import org.json.JSONException; 8 | import org.json.JSONObject; 9 | 10 | import android.os.Parcel; 11 | import android.os.Parcelable; 12 | 13 | public class MultiLineString extends Geometry { 14 | 15 | // ------------------------------------------------------------------------ 16 | // Instance Variables 17 | // ------------------------------------------------------------------------ 18 | 19 | private final List mLineStrings = new ArrayList(); 20 | 21 | // ------------------------------------------------------------------------ 22 | // Constructors 23 | // ------------------------------------------------------------------------ 24 | 25 | public MultiLineString() { 26 | // Default Constructor 27 | } 28 | 29 | public MultiLineString(JSONObject json) { 30 | super(json); 31 | 32 | this.setLineStrings(json.optJSONArray(JSON_COORDINATES)); 33 | } 34 | 35 | public MultiLineString(JSONArray lineStrings) { 36 | this.setLineStrings(lineStrings); 37 | } 38 | 39 | // ------------------------------------------------------------------------ 40 | // Parcelable Interface 41 | // ------------------------------------------------------------------------ 42 | 43 | public static final Parcelable.Creator CREATOR = new Creator() { 44 | @Override 45 | public MultiLineString createFromParcel(Parcel in) { 46 | return (MultiLineString) readParcel(in); 47 | } 48 | 49 | @Override 50 | public MultiLineString[] newArray(int size) { 51 | return new MultiLineString[size]; 52 | } 53 | }; 54 | 55 | // ------------------------------------------------------------------------ 56 | // Public Methods 57 | // ------------------------------------------------------------------------ 58 | 59 | public void addLineString(LineString lineString) { 60 | this.mLineStrings.add(lineString); 61 | } 62 | 63 | public void removeLineString(LineString lineString) { 64 | this.mLineStrings.remove(lineString); 65 | } 66 | 67 | public List getLineStrings() { 68 | return this.mLineStrings; 69 | } 70 | 71 | public void setLineStrings(JSONArray lineStrings) { 72 | this.mLineStrings.clear(); 73 | if (lineStrings != null) { 74 | for (int i = 0; i < lineStrings.length(); i++) { 75 | JSONArray lineJSON = lineStrings.optJSONArray(i); 76 | if (lineJSON != null) { 77 | this.mLineStrings.add(new LineString(lineJSON)); 78 | } 79 | } 80 | } 81 | } 82 | 83 | public void setLineStrings(List lineStrings) { 84 | this.mLineStrings.clear(); 85 | if (lineStrings != null) { 86 | this.mLineStrings.addAll(lineStrings); 87 | } 88 | } 89 | 90 | @Override 91 | public String getType() { 92 | return GeoJSON.TYPE_MULTI_LINE_STRING; 93 | } 94 | 95 | @Override 96 | public JSONObject toJSON() throws JSONException { 97 | JSONObject json = super.toJSON(); 98 | 99 | JSONArray strings = new JSONArray(); 100 | for (LineString line : this.mLineStrings) { 101 | JSONArray lineJSON = new JSONArray(); 102 | for (Position position : line.getPositions()) { 103 | lineJSON.put(position.toJSON()); 104 | } 105 | strings.put(lineJSON); 106 | } 107 | json.put(JSON_COORDINATES, strings); 108 | 109 | return json; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiPoint.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import java.util.List; 4 | 5 | import org.json.JSONArray; 6 | import org.json.JSONException; 7 | import org.json.JSONObject; 8 | 9 | import android.os.Parcel; 10 | import android.os.Parcelable; 11 | 12 | public class MultiPoint extends Geometry { 13 | 14 | // ------------------------------------------------------------------------ 15 | // Instance Variables 16 | // ------------------------------------------------------------------------ 17 | 18 | private final PositionList mPositionList = new PositionList(); 19 | 20 | // ------------------------------------------------------------------------ 21 | // Constructors 22 | // ------------------------------------------------------------------------ 23 | 24 | public MultiPoint() { 25 | // Default Constructor 26 | } 27 | 28 | public MultiPoint(JSONObject json) { 29 | super(json); 30 | 31 | this.setPositions(json.optJSONArray(JSON_COORDINATES)); 32 | } 33 | 34 | public MultiPoint(JSONArray positions) { 35 | this.setPositions(positions); 36 | } 37 | 38 | // ------------------------------------------------------------------------ 39 | // Parcelable Interface 40 | // ------------------------------------------------------------------------ 41 | 42 | public static final Parcelable.Creator CREATOR = new Creator() { 43 | @Override 44 | public MultiPoint createFromParcel(Parcel in) { 45 | return (MultiPoint) readParcel(in); 46 | } 47 | 48 | @Override 49 | public MultiPoint[] newArray(int size) { 50 | return new MultiPoint[size]; 51 | } 52 | }; 53 | 54 | // ------------------------------------------------------------------------ 55 | // Public Methods 56 | // ------------------------------------------------------------------------ 57 | 58 | public void addPosition(Position position) { 59 | this.mPositionList.addPosition(position); 60 | } 61 | 62 | public void removePosition(Position position) { 63 | this.mPositionList.removePosition(position); 64 | } 65 | 66 | public List getPositions() { 67 | return this.mPositionList.getPositions(); 68 | } 69 | 70 | public void setPositions(JSONArray positions) { 71 | this.mPositionList.setPositions(positions); 72 | } 73 | 74 | public void setPositions(List positions) { 75 | this.mPositionList.setPositions(positions); 76 | } 77 | 78 | @Override 79 | public String getType() { 80 | return GeoJSON.TYPE_MULTI_POINT; 81 | } 82 | 83 | @Override 84 | public JSONObject toJSON() throws JSONException { 85 | JSONObject json = super.toJSON(); 86 | 87 | json.put(JSON_COORDINATES, this.mPositionList.toJSON()); 88 | 89 | return json; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiPolygon.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.json.JSONArray; 7 | import org.json.JSONException; 8 | import org.json.JSONObject; 9 | 10 | import android.os.Parcel; 11 | import android.os.Parcelable; 12 | 13 | public class MultiPolygon extends Geometry { 14 | 15 | // ------------------------------------------------------------------------ 16 | // Instance Variables 17 | // ------------------------------------------------------------------------ 18 | 19 | private final List mPolygons = new ArrayList(); 20 | 21 | // ------------------------------------------------------------------------ 22 | // Constructors 23 | // ------------------------------------------------------------------------ 24 | 25 | public MultiPolygon() { 26 | // Default Constructor 27 | } 28 | 29 | public MultiPolygon(JSONObject json) { 30 | super(json); 31 | 32 | this.setPolygons(json.optJSONArray(JSON_COORDINATES)); 33 | } 34 | 35 | // ------------------------------------------------------------------------ 36 | // Parcelable Interface 37 | // ------------------------------------------------------------------------ 38 | 39 | public static final Parcelable.Creator CREATOR = new Creator() { 40 | @Override 41 | public MultiPolygon createFromParcel(Parcel in) { 42 | return (MultiPolygon) readParcel(in); 43 | } 44 | 45 | @Override 46 | public MultiPolygon[] newArray(int size) { 47 | return new MultiPolygon[size]; 48 | } 49 | }; 50 | 51 | // ------------------------------------------------------------------------ 52 | // Public Methods 53 | // ------------------------------------------------------------------------ 54 | 55 | public void addPolygon(Polygon polygon) { 56 | this.mPolygons.add(polygon); 57 | } 58 | 59 | public void removePolygon(Polygon polygon) { 60 | this.mPolygons.remove(polygon); 61 | } 62 | 63 | public List getPolygons() { 64 | return this.mPolygons; 65 | } 66 | 67 | public void setPolygons(JSONArray polygons) { 68 | this.mPolygons.clear(); 69 | if (polygons != null) { 70 | for (int i = 0; i < polygons.length(); i++) { 71 | JSONArray polyJSON = polygons.optJSONArray(i); 72 | if (polyJSON != null) { 73 | this.mPolygons.add(new Polygon(polyJSON)); 74 | } 75 | } 76 | } 77 | } 78 | 79 | public void setPolygons(List polygons) { 80 | this.mPolygons.clear(); 81 | if (polygons != null) { 82 | this.mPolygons.addAll(polygons); 83 | } 84 | } 85 | 86 | @Override 87 | public String getType() { 88 | return GeoJSON.TYPE_MULTI_POLYGON; 89 | } 90 | 91 | @Override 92 | public JSONObject toJSON() throws JSONException { 93 | JSONObject json = super.toJSON(); 94 | 95 | JSONArray polygons = new JSONArray(); 96 | for (Polygon polygon : this.mPolygons) { 97 | JSONArray ringJSON = new JSONArray(); 98 | for (Ring ring : polygon.getRings()) { 99 | ringJSON.put(ring.toJSON()); 100 | } 101 | polygons.put(ringJSON); 102 | } 103 | json.put(JSON_COORDINATES, polygons); 104 | 105 | return json; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/Point.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONException; 5 | import org.json.JSONObject; 6 | 7 | import android.os.Parcel; 8 | import android.os.Parcelable; 9 | 10 | public class Point extends Geometry { 11 | 12 | // ------------------------------------------------------------------------ 13 | // Instance Variables 14 | // ------------------------------------------------------------------------ 15 | 16 | private Position mPosition; 17 | 18 | // ------------------------------------------------------------------------ 19 | // Constructors 20 | // ------------------------------------------------------------------------ 21 | 22 | public Point() { 23 | // Default Constructor 24 | } 25 | 26 | public Point(JSONObject json) { 27 | super(json); 28 | 29 | this.setPosition(json.optJSONArray(JSON_COORDINATES)); 30 | } 31 | 32 | public Point(JSONArray position) { 33 | this.setPosition(position); 34 | } 35 | 36 | public Point(Position position) { 37 | this.setPosition(position); 38 | } 39 | 40 | public Point(double latitude, double longitude) { 41 | this.mPosition = new Position(latitude, longitude); 42 | } 43 | 44 | public Point(double latitude, double longitude, double altitude) { 45 | this.mPosition = new Position(latitude, longitude, altitude); 46 | } 47 | 48 | // ------------------------------------------------------------------------ 49 | // Parcelable Interface 50 | // ------------------------------------------------------------------------ 51 | 52 | public static final Parcelable.Creator CREATOR = new Creator() { 53 | @Override 54 | public Point createFromParcel(Parcel in) { 55 | return (Point) readParcel(in); 56 | } 57 | 58 | @Override 59 | public Point[] newArray(int size) { 60 | return new Point[size]; 61 | } 62 | }; 63 | 64 | // ------------------------------------------------------------------------ 65 | // Public Methods 66 | // ------------------------------------------------------------------------ 67 | 68 | public Position getPosition() { 69 | return this.mPosition; 70 | } 71 | 72 | public void setPosition(Position position) { 73 | this.mPosition = position; 74 | } 75 | 76 | public void setPosition(JSONArray position) { 77 | if (position != null) { 78 | this.mPosition = new Position(position); 79 | } 80 | else { 81 | this.mPosition = null; 82 | } 83 | } 84 | 85 | @Override 86 | public String getType() { 87 | return GeoJSON.TYPE_POINT; 88 | } 89 | 90 | @Override 91 | public JSONObject toJSON() throws JSONException { 92 | JSONObject json = super.toJSON(); 93 | 94 | if (this.mPosition != null) { 95 | json.put(JSON_COORDINATES, this.mPosition.toJSON()); 96 | } 97 | 98 | return json; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/Polygon.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.json.JSONArray; 7 | import org.json.JSONException; 8 | import org.json.JSONObject; 9 | 10 | import android.os.Parcel; 11 | import android.os.Parcelable; 12 | 13 | public class Polygon extends Geometry { 14 | 15 | // ------------------------------------------------------------------------ 16 | // Instance Variables 17 | // ------------------------------------------------------------------------ 18 | 19 | private final List mRings = new ArrayList(); 20 | 21 | // ------------------------------------------------------------------------ 22 | // Constructors 23 | // ------------------------------------------------------------------------ 24 | 25 | public Polygon() { 26 | // Default Constructor 27 | } 28 | 29 | public Polygon(Ring ring) { 30 | this.addRing(ring); 31 | } 32 | 33 | public Polygon(JSONObject json) { 34 | super(json); 35 | 36 | this.setRings(json.optJSONArray(JSON_COORDINATES)); 37 | } 38 | 39 | public Polygon(JSONArray rings) { 40 | this.setRings(rings); 41 | } 42 | 43 | // ------------------------------------------------------------------------ 44 | // Parcelable Interface 45 | // ------------------------------------------------------------------------ 46 | 47 | public static final Parcelable.Creator CREATOR = new Creator() { 48 | @Override 49 | public Polygon createFromParcel(Parcel in) { 50 | return (Polygon) readParcel(in); 51 | } 52 | 53 | @Override 54 | public Polygon[] newArray(int size) { 55 | return new Polygon[size]; 56 | } 57 | }; 58 | 59 | // ------------------------------------------------------------------------ 60 | // Public Methods 61 | // ------------------------------------------------------------------------ 62 | 63 | public void addRing(Ring ring) { 64 | this.mRings.add(ring); 65 | } 66 | 67 | public void removeRing(Ring ring) { 68 | this.mRings.remove(ring); 69 | } 70 | 71 | public List getRings() { 72 | return this.mRings; 73 | } 74 | 75 | public void setRings(JSONArray rings) { 76 | this.mRings.clear(); 77 | if (rings != null) { 78 | for (int i = 0; i < rings.length(); i++) { 79 | JSONArray ringJSON = rings.optJSONArray(i); 80 | if (ringJSON != null) { 81 | this.mRings.add(new Ring(ringJSON)); 82 | } 83 | } 84 | } 85 | } 86 | 87 | public void setRings(List rings) { 88 | this.mRings.clear(); 89 | if (rings != null) { 90 | this.mRings.addAll(rings); 91 | } 92 | } 93 | 94 | @Override 95 | public String getType() { 96 | return GeoJSON.TYPE_POLYGON; 97 | } 98 | 99 | @Override 100 | public JSONObject toJSON() throws JSONException { 101 | JSONObject json = super.toJSON(); 102 | 103 | JSONArray rings = new JSONArray(); 104 | for (Ring ring : this.mRings) { 105 | rings.put(ring.toJSON()); 106 | } 107 | json.put(JSON_COORDINATES, rings); 108 | 109 | return json; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/Position.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.json.JSONArray; 6 | import org.json.JSONException; 7 | 8 | import android.location.Location; 9 | import android.os.Parcel; 10 | import android.os.Parcelable; 11 | 12 | public class Position implements Parcelable { 13 | 14 | // ------------------------------------------------------------------------ 15 | // Private Constants 16 | // ------------------------------------------------------------------------ 17 | 18 | private static final int LON_IDX = 0; 19 | 20 | private static final int LAT_IDX = 1; 21 | 22 | private static final int ALT_IDX = 2; 23 | 24 | // ------------------------------------------------------------------------ 25 | // Instance Variables 26 | // ------------------------------------------------------------------------ 27 | 28 | private final double[] mStorage = new double[3]; 29 | 30 | // ------------------------------------------------------------------------ 31 | // Constructors 32 | // ------------------------------------------------------------------------ 33 | 34 | public Position(JSONArray array) { 35 | this.mStorage[LON_IDX] = array.optDouble(LON_IDX, 0); 36 | this.mStorage[LAT_IDX] = array.optDouble(LAT_IDX, 0); 37 | this.mStorage[ALT_IDX] = array.optDouble(ALT_IDX, 0); 38 | } 39 | 40 | public Position(double[] array) { 41 | if (array.length == 2) { 42 | this.mStorage[LON_IDX] = array[LON_IDX]; 43 | this.mStorage[LAT_IDX] = array[LAT_IDX]; 44 | } 45 | else if (array.length == 3) { 46 | this.mStorage[LON_IDX] = array[LON_IDX]; 47 | this.mStorage[LAT_IDX] = array[LAT_IDX]; 48 | this.mStorage[ALT_IDX] = array[ALT_IDX]; 49 | } 50 | } 51 | 52 | public Position(double latitude, double longitude) { 53 | this.mStorage[LAT_IDX] = latitude; 54 | this.mStorage[LON_IDX] = longitude; 55 | } 56 | 57 | public Position(double latitude, double longitude, double altitude) { 58 | this.mStorage[LAT_IDX] = latitude; 59 | this.mStorage[LON_IDX] = longitude; 60 | this.mStorage[ALT_IDX] = altitude; 61 | } 62 | 63 | public Position(Location location) { 64 | this.mStorage[LAT_IDX] = location.getLatitude(); 65 | this.mStorage[LON_IDX] = location.getLongitude(); 66 | this.mStorage[ALT_IDX] = location.getAltitude(); 67 | } 68 | 69 | private Position(Parcel parcel) { 70 | this(parcel.createDoubleArray()); 71 | } 72 | 73 | // ------------------------------------------------------------------------ 74 | // Parcelable Interface 75 | // ------------------------------------------------------------------------ 76 | 77 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 78 | @Override 79 | public Position createFromParcel(Parcel in) { 80 | return new Position(in); 81 | } 82 | 83 | @Override 84 | public Position[] newArray(int size) { 85 | return new Position[size]; 86 | } 87 | }; 88 | 89 | @Override 90 | public int describeContents() { 91 | return 0; 92 | } 93 | 94 | @Override 95 | public void writeToParcel(Parcel dest, int flags) { 96 | dest.writeDoubleArray(this.mStorage); 97 | } 98 | 99 | // ------------------------------------------------------------------------ 100 | // Public Methods 101 | // ------------------------------------------------------------------------ 102 | 103 | public double getLatitude() { 104 | return this.mStorage[LAT_IDX]; 105 | } 106 | 107 | public void setLatitude(double latitude) { 108 | this.mStorage[LAT_IDX] = latitude; 109 | } 110 | 111 | public double getLongitude() { 112 | return this.mStorage[LON_IDX]; 113 | } 114 | 115 | public void setLongitude(double longitude) { 116 | this.mStorage[LON_IDX] = longitude; 117 | } 118 | 119 | public double getAltitude() { 120 | return this.mStorage[ALT_IDX]; 121 | } 122 | 123 | public void setAltitude(double altitude) { 124 | this.mStorage[ALT_IDX] = altitude; 125 | } 126 | 127 | public JSONArray toJSON() throws JSONException { 128 | JSONArray coordinates = new JSONArray(); 129 | 130 | coordinates.put(LAT_IDX, this.getLatitude()); 131 | coordinates.put(LON_IDX, this.getLongitude()); 132 | coordinates.put(ALT_IDX, this.getAltitude()); 133 | 134 | return coordinates; 135 | } 136 | 137 | public Location toLocation() { 138 | Location location = new Location("GeoJSON"); 139 | 140 | location.setLatitude(this.getLatitude()); 141 | location.setLongitude(this.getLongitude()); 142 | location.setAltitude(this.getAltitude()); 143 | 144 | return location; 145 | } 146 | 147 | public double[] toArray() { 148 | return this.mStorage; 149 | } 150 | 151 | @Override 152 | public boolean equals(Object object) { 153 | if (this == object) { 154 | return true; 155 | } 156 | 157 | if (!(object instanceof Position)) { 158 | return false; 159 | } 160 | 161 | Position aPosition = (Position) object; 162 | 163 | return Arrays.equals(this.mStorage, aPosition.mStorage); 164 | } 165 | 166 | @Override 167 | public int hashCode() { 168 | return Arrays.hashCode(this.mStorage); 169 | } 170 | 171 | @Override 172 | public String toString() { 173 | return Arrays.toString(this.mStorage); 174 | } 175 | 176 | } 177 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/PositionList.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.json.JSONArray; 7 | import org.json.JSONException; 8 | 9 | import android.os.Parcel; 10 | import android.os.Parcelable; 11 | 12 | import com.cocoahero.android.geojson.util.ListUtils; 13 | 14 | public class PositionList implements Parcelable { 15 | 16 | // ------------------------------------------------------------------------ 17 | // Instance Variables 18 | // ------------------------------------------------------------------------ 19 | 20 | private final List mPositions = new ArrayList(); 21 | 22 | // ------------------------------------------------------------------------ 23 | // Constructors 24 | // ------------------------------------------------------------------------ 25 | 26 | public PositionList() { 27 | // Default Constructor 28 | } 29 | 30 | public PositionList(JSONArray positions) { 31 | this.setPositions(positions); 32 | } 33 | 34 | public PositionList(double[][] positions) { 35 | for (int i = 0; i < positions.length; i++) { 36 | this.addPosition(new Position(positions[i])); 37 | } 38 | } 39 | 40 | protected PositionList(Parcel parcel) { 41 | this.setPositions(parcel.createTypedArrayList(Position.CREATOR)); 42 | } 43 | 44 | // ------------------------------------------------------------------------ 45 | // Parcelable Interface 46 | // ------------------------------------------------------------------------ 47 | 48 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 49 | @Override 50 | public PositionList createFromParcel(Parcel in) { 51 | return new PositionList(in); 52 | } 53 | 54 | @Override 55 | public PositionList[] newArray(int size) { 56 | return new PositionList[size]; 57 | } 58 | }; 59 | 60 | @Override 61 | public int describeContents() { 62 | return 0; 63 | } 64 | 65 | @Override 66 | public void writeToParcel(Parcel dest, int flags) { 67 | dest.writeTypedList(this.mPositions); 68 | } 69 | 70 | // ------------------------------------------------------------------------ 71 | // Public Methods 72 | // ------------------------------------------------------------------------ 73 | 74 | public List getPositions() { 75 | return this.mPositions; 76 | } 77 | 78 | public void addPosition(Position position) { 79 | this.mPositions.add(position); 80 | } 81 | 82 | public void addPositions(PositionList positions) { 83 | this.mPositions.addAll(positions.mPositions); 84 | } 85 | 86 | public void addPositions(List positions) { 87 | this.mPositions.addAll(positions); 88 | } 89 | 90 | public void removePosition(Position position) { 91 | this.mPositions.remove(position); 92 | } 93 | 94 | public void removePositions(PositionList positions) { 95 | this.mPositions.removeAll(positions.mPositions); 96 | } 97 | 98 | public void removePositions(List positions) { 99 | this.mPositions.removeAll(positions); 100 | } 101 | 102 | public void clearPositions() { 103 | this.mPositions.clear(); 104 | } 105 | 106 | public void setPositions(JSONArray positions) { 107 | this.mPositions.clear(); 108 | if (positions != null) { 109 | for (int i = 0; i < positions.length(); i++) { 110 | JSONArray position = positions.optJSONArray(i); 111 | if (position != null) { 112 | this.mPositions.add(new Position(position)); 113 | } 114 | } 115 | } 116 | } 117 | 118 | public void setPositions(PositionList positions) { 119 | this.mPositions.clear(); 120 | if (positions != null) { 121 | this.mPositions.addAll(positions.mPositions); 122 | } 123 | } 124 | 125 | public void setPositions(List positions) { 126 | this.mPositions.clear(); 127 | if (positions != null) { 128 | this.mPositions.addAll(positions); 129 | } 130 | } 131 | 132 | public Position getHead() { 133 | return ListUtils.getHead(this.mPositions); 134 | } 135 | 136 | public Position getTail() { 137 | return ListUtils.getTail(this.mPositions); 138 | } 139 | 140 | public boolean isLinearRing() { 141 | if (this.mPositions.size() < 4) { 142 | return false; 143 | } 144 | 145 | Position head = this.getHead(); 146 | Position tail = this.getTail(); 147 | 148 | return head.equals(tail); 149 | } 150 | 151 | public JSONArray toJSON() throws JSONException { 152 | JSONArray positions = new JSONArray(); 153 | 154 | for (Position position : this.mPositions) { 155 | positions.put(position.toJSON()); 156 | } 157 | 158 | return positions; 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/Ring.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson; 2 | 3 | import org.json.JSONArray; 4 | 5 | import android.os.Parcel; 6 | import android.os.Parcelable; 7 | 8 | public class Ring extends PositionList { 9 | 10 | // ------------------------------------------------------------------------ 11 | // Constructors 12 | // ------------------------------------------------------------------------ 13 | 14 | public Ring() { 15 | // Default Constructor 16 | } 17 | 18 | public Ring(JSONArray positions) { 19 | super(positions); 20 | } 21 | 22 | public Ring(double[][] positions) { 23 | super(positions); 24 | } 25 | 26 | protected Ring(Parcel parcel) { 27 | super(parcel); 28 | } 29 | 30 | // ------------------------------------------------------------------------ 31 | // Parcelable Interface 32 | // ------------------------------------------------------------------------ 33 | 34 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 35 | @Override 36 | public Ring createFromParcel(Parcel in) { 37 | return new Ring(in); 38 | } 39 | 40 | @Override 41 | public Ring[] newArray(int size) { 42 | return new Ring[size]; 43 | } 44 | }; 45 | 46 | // ------------------------------------------------------------------------ 47 | // Public Methods 48 | // ------------------------------------------------------------------------ 49 | 50 | public void close() { 51 | if (!this.isLinearRing()) { 52 | this.addPosition(this.getHead()); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/util/JSONUtils.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson.util; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONObject; 5 | 6 | public class JSONUtils { 7 | 8 | public static boolean isEmpty(JSONObject json) { 9 | return (json == null) || (json.length() <= 0); 10 | } 11 | 12 | public static boolean isEmpty(JSONArray json) { 13 | return (json == null) || (json.length() <= 0); 14 | } 15 | 16 | public static String optString(JSONObject json, String name) { 17 | return optString(json, name, null); 18 | } 19 | 20 | public static String optString(JSONObject json, String name, String fallback) { 21 | if (json != null) { 22 | if (!json.isNull(name)) { 23 | return json.optString(name, fallback); 24 | } 25 | return fallback; 26 | } 27 | return null; 28 | } 29 | 30 | public static String optString(JSONArray json, int index) { 31 | return optString(json, index, null); 32 | } 33 | 34 | public static String optString(JSONArray json, int index, String fallback) { 35 | if (json != null) { 36 | if (!json.isNull(index)) { 37 | return json.optString(index, fallback); 38 | } 39 | return fallback; 40 | } 41 | return null; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/util/ListUtils.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson.util; 2 | 3 | import java.util.List; 4 | 5 | public class ListUtils { 6 | 7 | public static T getHead(List list) { 8 | if (list == null || list.isEmpty()) { 9 | return null; 10 | } 11 | return list.get(0); 12 | } 13 | 14 | public static T getTail(List list) { 15 | if (list == null || list.isEmpty()) { 16 | return null; 17 | } 18 | return list.get(list.size() - 1); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /androidgeojson/src/main/java/com/cocoahero/android/geojson/util/StreamUtils.java: -------------------------------------------------------------------------------- 1 | package com.cocoahero.android.geojson.util; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.InputStreamReader; 6 | 7 | public class StreamUtils { 8 | 9 | /** 10 | * Decodes the contents of the provided {@link InputStream} into a 11 | * {@link String} using the UTF-8 charset. 12 | * 13 | * @param byteStream The {@link InputStream} to decode. 14 | * @return A {@link String} representation of the stream's contents. 15 | * @throws IOException 16 | */ 17 | public static String toString(InputStream byteStream) throws IOException { 18 | return toString(byteStream, "UTF-8"); 19 | } 20 | 21 | /** 22 | * Decodes the contents of the provided {@link InputStream} into a 23 | * {@link String} using the charset denoted by the charsetName parameter. 24 | * 25 | * @param byteStream The {@link InputStream} to decode. 26 | * @param charsetName The charset used to decode the stream. 27 | * @return A {@link String} representation of the stream's contents. 28 | * @throws IOException 29 | */ 30 | public static String toString(InputStream byteStream, String charsetName) throws IOException { 31 | char[] buffer = new char[1024]; 32 | 33 | StringBuilder builder = new StringBuilder(); 34 | 35 | InputStreamReader reader = new InputStreamReader(byteStream, charsetName); 36 | 37 | for (int length = 0; (length = reader.read(buffer)) >= 0;) { 38 | builder.append(buffer, 0, length); 39 | } 40 | 41 | reader.close(); 42 | 43 | return builder.toString(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | repositories { 4 | mavenCentral() 5 | } 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:1.1.3' 8 | } 9 | } 10 | 11 | allprojects { 12 | repositories { 13 | mavenCentral() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocoahero/android-geojson/eec45c0a5429d5c8fb0c2536e135084f87aa958a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 13 10:21:30 CST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | android.library=true 16 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':androidgeojson' 2 | --------------------------------------------------------------------------------