Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added to GeoFeature the ability to turn itself into a "Thing", way ha…
…rder than it has any right to be, simple udf that calls that function
- Loading branch information
Jacob Perkins
committed
Aug 3, 2011
1 parent
38c5cd3
commit 25a62b8
Showing
5 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/infochimps/hadoop/pig/geo/GeoJSONToThing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
package com.infochimps.hadoop.pig.geo; | |||
|
|||
import java.io.IOException; | |||
import java.util.HashMap; | |||
|
|||
import org.apache.pig.EvalFunc; | |||
import org.apache.pig.data.Tuple; | |||
import org.apache.pig.data.DataBag; | |||
import org.apache.pig.data.TupleFactory; | |||
|
|||
import org.mapfish.geo.MfGeo; | |||
import org.mapfish.geo.MfGeoFactory; | |||
import org.mapfish.geo.MfGeoJSONReader; | |||
import org.mapfish.geo.MfGeometry; | |||
import org.mapfish.geo.MfFeature; | |||
|
|||
import com.vividsolutions.jts.geom.Polygon; | |||
import com.vividsolutions.jts.geom.Geometry; | |||
import com.vividsolutions.jts.geom.Point; | |||
import com.vividsolutions.jts.geom.Coordinate; | |||
|
|||
import org.json.JSONException; | |||
import org.json.JSONObject; | |||
|
|||
/** | |||
Given a geoJSON feature, mangles it into an ICSS 'Thing'. | |||
*/ | |||
public class GeoJSONToThing extends EvalFunc<String> { | |||
private final MfGeoFactory mfFactory = new MfGeoFactory() { | |||
public MfFeature createFeature(String id, MfGeometry geometry, JSONObject properties) { | |||
return new GeoFeature(id, geometry, properties); | |||
} | |||
}; | |||
|
|||
private final MfGeoJSONReader reader = new MfGeoJSONReader(mfFactory); | |||
|
|||
private static final String PERIOD = "\\."; | |||
private static final String GEOJSON_ID = "id"; | |||
private static final String GEOJSON_TYPE = "type"; | |||
private static final String GEOJSON_FEATURE = "Feature"; | |||
private static final String GEOJSON_GEOM = "geometry"; | |||
private static final String GEOJSON_PROP = "properties"; | |||
|
|||
public String exec(Tuple input) throws IOException { | |||
if (input == null || input.size() < 1 || input.isNull(0)) | |||
return null; | |||
|
|||
String json = input.get(0).toString(); | |||
String result = null; | |||
try { | |||
GeoFeature feature = (GeoFeature)reader.decode(json); | |||
result = feature.toIcssThing(); | |||
} catch (JSONException e) {} | |||
return result; | |||
} | |||
} |