本文整理匯總了Java中com.vividsolutions.jts.geom.Geometry.getUserData方法的典型用法代碼示例。如果您正苦於以下問題:Java Geometry.getUserData方法的具體用法?Java Geometry.getUserData怎麽用?Java Geometry.getUserData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.vividsolutions.jts.geom.Geometry
的用法示例。
在下文中一共展示了Geometry.getUserData方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDates
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
public Date[] getDates() {
Date[] out = new Date[2];
out[1] = new Date(0);
out[0] = new Date(Long.MAX_VALUE);
for (Geometry g : glayer.getGeometries()) {
AttributesGeometry at=(AttributesGeometry)g.getUserData();
Date temp = (Date) at.get(timeColumn);
if (out[0].after(temp)) {
out[0] = temp;
}
if (out[1].before(temp)) {
out[1] = temp;
}
}
return out;
}
示例2: printGeoms
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* Print geometries.
*
* @param geoms the geometries
* @throws IOException thrown when IO error
*/
public static void printGeoms(Collection<Geometry> geoms) throws IOException {
System.out.println("Attribute Info");
System.out.println("---------------");
for (Geometry geom : geoms) {
if (geom.getUserData() == null) {
System.out.println("no user data");
return;
}
Map<?,?> attributes = (Map) geom.getUserData();
for (Map.Entry entry : attributes.entrySet()) {
System.out.println(entry.getKey() + " -> " + entry.getValue());
}
System.out.println("");
}
}
示例3: calculateMaxMinTresh
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
private void calculateMaxMinTresh() {
minThresh = Double.MAX_VALUE;
maxThresh = Double.MIN_VALUE;
for (Geometry geoms : glayer.getGeometries()) {
AttributesGeometry att=(AttributesGeometry) geoms.getUserData();
double temp = new Double("" + att.get(VDSSchema.SIGNIFICANCE));
if (temp < minThresh) {
minThresh = temp;
}
if (temp > maxThresh) {
maxThresh = temp;
}
}
currentThresh = minThresh - 0.01;
}
示例4: getHistogram
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
public int[] getHistogram(int numClasses) {
if (threshable) {
int[] out = new int[numClasses];
for (Geometry g : glayer.getGeometries()) {
AttributesGeometry att=(AttributesGeometry) g.getUserData();
double temp = new Double("" + att.get(VDSSchema.SIGNIFICANCE));
int classe = (int) ((numClasses - 1) * (temp - minThresh) / (maxThresh - minThresh));
out[classe]++;
}
return out;
}
return null;
}
示例5: apply
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
private static Geometry apply(String disease, Geometry g) {
@SuppressWarnings("unchecked")
Map<String, Object> attributes = (Map<String, Object>) g.getUserData();
// create random timestamp
long measurementSpace = END - START;
long timestamp = START + (long) (Math.random() * measurementSpace);
attributes.put("timestamp", timestamp);
attributes.put("disease_name", disease);
g.setUserData(attributes);
return g;
}
示例6: getAttributes
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* retrun the atributes associated with the geometry
* @param geom
* @return
*/
public AttributesGeometry getAttributes(Geometry geom) {
if(!geoms.contains(geom))
return null;
return (AttributesGeometry)geom.getUserData();
}
示例7: exportGeometriesToShapeFile
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
*
* @param geoms
* @param fileOutput
* @param geomType
* @param transform
* @throws IOException
* @throws SchemaException
*/
public static void exportGeometriesToShapeFile(final List<Geometry> geoms,
File fileOutput,String geomType,GeoTransform transform,
SimpleFeatureType featureType) throws IOException, SchemaException{
FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();
//Map map = Collections.singletonMap( "url", fileOutput.toURI().toURL() );
DataStore data = factory.createDataStore( fileOutput.toURI().toURL() );
boolean addAttr=true;
if(featureType==null){
featureType=DataUtilities.createType( "the_geom", "geom:"+geomType+",name:String,age:Integer,description:String" );
addAttr=false;
}
data.createSchema( featureType );
Transaction transaction = new DefaultTransaction();
FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriterAppend(data.getTypeNames()[0], transaction);
SimpleFeatureBuilder featureBuilder=new SimpleFeatureBuilder(featureType);
GeometryFactory gb=new GeometryFactory();
try {
int fid=0;
for(final Geometry g:geoms){
Geometry clone=gb.createGeometry(g);
if(transform!=null)
clone=transform.transformGeometryGeoFromPixel(clone);
featureBuilder.add("the_geom");
featureBuilder.add(clone);
SimpleFeature sf=featureBuilder.buildFeature(""+fid++);
SimpleFeature sfout=writer.next();
sfout.setAttributes( sf.getAttributes() );
//setting attributes geometry
AttributesGeometry att=(AttributesGeometry) g.getUserData();
try{
if(att!=null&&addAttr){
String sch[]=att.getSchema();
for(int i=0;i<sch.length;i++){
Object val=att.get(sch[i]);
if(val.getClass().isArray()){
Object o=ArrayUtils.toString(val);
sfout.setAttribute(sch[i], o);
}else{
sfout.setAttribute(sch[i], val);
}
}
}
}catch(Exception e ){
logger.warn("Error adding attributes to geometry:"+e.getMessage());
}
sfout.setDefaultGeometry( clone);
writer.write();
}
transaction.commit();
logger.info("Export to shapefile complete:"+ fileOutput.getAbsolutePath());
} catch (Exception problem) {
problem.printStackTrace();
transaction.rollback();
logger.error("Export to shapefile failed",problem );
} finally {
writer.close();
transaction.close();
data.dispose();
}
}
示例8: createTileGeom
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* <p>Create geometry clipped and then converted to MVT 'extent' coordinates. Result
* contains both clipped geometry (intersection) and transformed geometry for encoding to
* MVT.</p>
* <p>Allows specifying separate tile and clipping coordinates. {@code clipEnvelope} can be bigger
* than {@code tileEnvelope} to have geometry exist outside the MVT tile extent.</p>
*
* @param geometryList original 'source' geometry, passed through
* {@link #flatFeatureList(Geometry)}
* @param tileEnvelope world coordinate bounds for tile, used for transforms
* @param clipEnvelope world coordinates to clip tile by
* @param geomFactory creates a geometry for the tile envelope
* @param mvtLayerParams specifies vector tile properties
* @param filter geometry values that fail filter after transforms are removed
* @return tile geometry result
* @see TileGeomResult
*/
public static TileGeomResult createTileGeom(List<Geometry> geometryList,
Envelope tileEnvelope,
Envelope clipEnvelope,
GeometryFactory geomFactory,
MvtLayerParams mvtLayerParams,
IGeometryFilter filter) {
final Geometry tileClipGeom = geomFactory.toGeometry(clipEnvelope);
final AffineTransformation t = new AffineTransformation();
final double xDiff = tileEnvelope.getWidth();
final double yDiff = tileEnvelope.getHeight();
final double xOffset = -tileEnvelope.getMinX();
final double yOffset = -tileEnvelope.getMinY();
// Transform Setup: Shift to 0 as minimum value
t.translate(xOffset, yOffset);
// Transform Setup: Scale X and Y to tile extent values, flip Y values
t.scale(1d / (xDiff / (double) mvtLayerParams.extent),
-1d / (yDiff / (double) mvtLayerParams.extent));
// Transform Setup: Bump Y values to positive quadrant
t.translate(0d, (double) mvtLayerParams.extent);
// The area contained in BOTH the 'original geometry', g, AND the 'clip envelope geometry' is
// the 'tile geometry'
final List<Geometry> intersectedGeoms = flatIntersection(tileClipGeom, geometryList);
final List<Geometry> transformedGeoms = new ArrayList<>(intersectedGeoms.size());
// Transform intersected geometry
Geometry nextTransformGeom;
Object nextUserData;
for (Geometry nextInterGeom : intersectedGeoms) {
nextUserData = nextInterGeom.getUserData();
nextTransformGeom = t.transform(nextInterGeom);
// Floating --> Integer, still contained within doubles
nextTransformGeom.apply(RoundingFilter.INSTANCE);
// TODO: Refactor line simplification
// Can't use 0d, specify value < .5d
nextTransformGeom = TopologyPreservingSimplifier.simplify(nextTransformGeom, .1d);
nextTransformGeom.setUserData(nextUserData);
// Apply filter on transformed geometry
if (filter.accept(nextTransformGeom)) {
transformedGeoms.add(nextTransformGeom);
}
}
return new TileGeomResult(intersectedGeoms, transformedGeoms);
}