当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.close方法代码示例

本文整理汇总了Java中org.geotools.data.Transaction.close方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.close方法的具体用法?Java Transaction.close怎么用?Java Transaction.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.geotools.data.Transaction的用法示例。


在下文中一共展示了Transaction.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeLineLayer

import org.geotools.data.Transaction; //导入方法依赖的package包/类
private void makeLineLayer( IEpanetType[] types, File baseFolder, CoordinateReferenceSystem mapCrs )
        throws MalformedURLException, IOException {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    String shapefileName = types[0].getShapefileName();
    String typeName = types[0].getName();
    b.setName(typeName);
    b.setCRS(mapCrs);
    b.add("the_geom", LineString.class);
    for( IEpanetType type : types ) {
        b.add(type.getAttributeName(), type.getClazz());
    }
    SimpleFeatureType tanksType = b.buildFeatureType();
    ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
    File file = new File(baseFolder, shapefileName);
    Map<String, Serializable> create = new HashMap<String, Serializable>();
    create.put("url", file.toURI().toURL());
    ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create);
    newDataStore.createSchema(tanksType);
    Transaction transaction = new DefaultTransaction();
    SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource();
    featureStore.setTransaction(transaction);
    try {
        featureStore.addFeatures(new DefaultFeatureCollection());
        transaction.commit();
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
    } finally {
        transaction.close();
    }
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:32,代码来源:OmsEpanetProjectFilesGenerator.java

示例2: exportToShapefile

import org.geotools.data.Transaction; //导入方法依赖的package包/类
/**
 * Export features to a new shapefile using the map projection in which
 * they are currently displayed
 */
 public static void exportToShapefile(DataStore newDataStore, FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)/*,SimpleFeatureType ftype)*/ throws Exception {
 // carefully open an iterator and writer to process the results
    Transaction transaction = new DefaultTransaction();
    FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriter(newDataStore.getTypeNames()[0],  transaction);

    FeatureIterator<SimpleFeature> iterator = featureCollection.features();
    try {

        while( iterator.hasNext() ){
            SimpleFeature feature = iterator.next();
            SimpleFeature copy = writer.next();


            //copy.setAttributes( feature.getAttributes() );
            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            if(geometry!=null){
            	copy.setDefaultGeometry( geometry.buffer(0));
            	writer.write();
            }else{
            	logger.warn("Warning:geometry null");
            }
        }
        transaction.commit();
        logger.info("Export to shapefile complete" );
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
        logger.error("Export to shapefile failed",problem );
    } finally {
        writer.close();
        iterator.close();
        transaction.close();
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:39,代码来源:SimpleShapefile.java

示例3: write

import org.geotools.data.Transaction; //导入方法依赖的package包/类
public static <T> void write(File file,
        Consumer<SimpleFeatureTypeBuilder> fun1,
        BiConsumer<SimpleFeatureBuilder, T> fun2,
        List<T> geometries) {
    try {
        SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
        typeBuilder.setName("MyFeatureType");
        typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
        fun1.accept(typeBuilder);
        SimpleFeatureType type = typeBuilder.buildFeatureType();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type);
        AtomicInteger id = new AtomicInteger(0);
        List<SimpleFeature> geoms = geometries.stream().map(g -> {
            fun2.accept(featureBuilder, g);
            return featureBuilder.buildFeature(String.valueOf(id.getAndIncrement()));
        }).collect(toList());
        ShapefileDataStoreFactory datastoreFactory = new ShapefileDataStoreFactory();
        Map<String, Serializable> params = newHashMap();
        params.put("url", file.toURI().toURL());
        params.put("create spatial index", Boolean.TRUE);
        ShapefileDataStore datastore = (ShapefileDataStore) datastoreFactory.createNewDataStore(params);
        datastore.createSchema(type);
        Transaction transaction = new DefaultTransaction("create");
        String typeName = datastore.getTypeNames()[0];
        SimpleFeatureSource featureSource = datastore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection collection = new ListFeatureCollection(type, geoms);
        featureStore.setTransaction(transaction);
        featureStore.addFeatures(collection);
        transaction.commit();
        transaction.close();
        datastore.dispose();
    }
    catch (IOException e) {
        throw propagate(e);
    }
}
 
开发者ID:Mappy,项目名称:fpm,代码行数:38,代码来源:ShapefileWriter.java

示例4: SoilSealingAdministrativeUnit

import org.geotools.data.Transaction; //导入方法依赖的package包/类
/**
 * Default constructor
 * 
 * @param au
 * @param geoCodingReference
 * @param populationReference
 * @throws IOException
 */
public SoilSealingAdministrativeUnit(String au, FeatureTypeInfo geoCodingReference,
        FeatureTypeInfo populationReference) throws IOException {
    if (!au.contains("_")) {
        throw new IOException("Invalid Administrative Unit name");
    }
    this.geoCodingReference = geoCodingReference;
    this.populationReference = populationReference;
    this.name = au.split("_")[0];
    this.parent = au.split("_")[1];

    FeatureReader<SimpleFeatureType, SimpleFeature> ftReader = null;
    Transaction transaction = new DefaultTransaction();
    try {
        final JDBCDataStore ds = (JDBCDataStore) geoCodingReference.getStore().getDataStore(null);
        Filter nameFilter = ff.equals(ff.property("name"), ff.literal(this.name));
        Filter parentFilter = ff.equals(ff.property("parent"), ff.literal(this.parent));
        Filter queryFilter = ff.and(Arrays.asList(nameFilter, parentFilter));
        Query query = new Query(geoCodingReference.getFeatureType().getName().getLocalPart(), queryFilter);
        
        ftReader = ds.getFeatureReader(query, transaction);

        while (ftReader.hasNext()) {
            Feature feature = ftReader.next();
            this.type = AuType.getType((Integer) feature.getProperty("type").getValue());
            this.the_geom = (Geometry) feature.getDefaultGeometryProperty().getValue();
            break;
        }
    } finally {
        if (ftReader != null) {
            ftReader.close();
        }

        transaction.commit();
        transaction.close();
    }

    if (this.type == null || this.the_geom == null) {
        throw new IOException("Invalid Administrative Unit name: no record found!");
    }

    switch (this.type) {
    case MUNICIPALITY:
        loadPopulationStatistics(this);
        break;
    case DISTRICT:
    case REGION:
        loadSubs(this);
        break;
    default:
        break;
    }
}
 
开发者ID:geosolutions-it,项目名称:soil_sealing,代码行数:61,代码来源:SoilSealingAdministrativeUnit.java

示例5: loadPopulationStatistics

import org.geotools.data.Transaction; //导入方法依赖的package包/类
/**
 * 
 * @param soilSealingAdministrativeUnit
 * @throws IOException
 */
private void loadPopulationStatistics(SoilSealingAdministrativeUnit soilSealingAdministrativeUnit) throws IOException {
    FeatureReader<SimpleFeatureType, SimpleFeature> ftReader = null;
    Transaction transaction = new DefaultTransaction();
    try {
        final JDBCDataStore ds = (JDBCDataStore) populationReference.getStore().getDataStore(null);
        Filter auNameFilter = ff.equals(ff.property("au_name"), ff.literal(this.name));
        Filter queryFilter = ff.and(Arrays.asList(auNameFilter));
        Query query = new Query(populationReference.getFeatureType().getName().getLocalPart(), queryFilter);

        ftReader = ds.getFeatureReader(query, transaction);
        
        while (ftReader.hasNext()) {
            Feature feature = ftReader.next();
            Collection<Property> properties = feature.getProperties();
            for (Property prop : properties) {
                if (prop.getName().getLocalPart().startsWith("a_")) {
                    Object yearPopulationValue = prop.getValue();
                    if (yearPopulationValue != null) {
                        population.put(prop.getName().getLocalPart().split("a_")[1], ((BigDecimal) yearPopulationValue).intValue());
                    }
                }
            }
        }
    } finally {
        if (ftReader != null) {
            ftReader.close();
        }

        transaction.commit();
        transaction.close();
    }
}
 
开发者ID:geosolutions-it,项目名称:soil_sealing,代码行数:38,代码来源:SoilSealingAdministrativeUnit.java

示例6: collectionToShapeFile

import org.geotools.data.Transaction; //导入方法依赖的package包/类
/**
 * <p>
 * The easy way to create a shapefile from attributes and geometries
 * </p>
 * <p>
 * <b>NOTE: this doesn't support date attributes</b>
 * </p>
 * 
 * @param shapeFilePath the shapefile name
 * @param crs the destination crs
 * @param fet the featurecollection
 * @throws IOException 
 */
public static boolean collectionToShapeFile( String shapeFilePath, CoordinateReferenceSystem crs,
        SimpleFeatureCollection fet ) throws IOException {

    // Create the file you want to write to
    File file = null;
    if (shapeFilePath.toLowerCase().endsWith(".shp")) { //$NON-NLS-1$
        file = new File(shapeFilePath);
    } else {
        file = new File(shapeFilePath + ".shp"); //$NON-NLS-1$
    }

    ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();

    Map<String, Serializable> create = new HashMap<String, Serializable>();
    create.put("url", file.toURI().toURL());
    ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create);

    newDataStore.createSchema(fet.getSchema());
    if (crs != null)
        newDataStore.forceSchemaCRS(crs);
    Transaction transaction = new DefaultTransaction();
    SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource();
    featureStore.setTransaction(transaction);
    try {
        featureStore.addFeatures(fet);
        transaction.commit();
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
    } finally {
        transaction.close();
    }
    return true;
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:48,代码来源:FeatureUtilities.java

示例7: makePointLayer

import org.geotools.data.Transaction; //导入方法依赖的package包/类
private void makePointLayer( IEpanetType[] types, File baseFolder, CoordinateReferenceSystem mapCrs )
        throws MalformedURLException, IOException {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    String shapefileName = types[0].getShapefileName();
    String typeName = types[0].getName();
    b.setName(typeName);
    b.setCRS(mapCrs);
    b.add("the_geom", Point.class);
    for( IEpanetType type : types ) {
        b.add(type.getAttributeName(), type.getClazz());
    }
    SimpleFeatureType tanksType = b.buildFeatureType();
    ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
    File file = new File(baseFolder, shapefileName);
    Map<String, Serializable> create = new HashMap<String, Serializable>();
    create.put("url", file.toURI().toURL());
    ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create);
    newDataStore.createSchema(tanksType);
    Transaction transaction = new DefaultTransaction();
    SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource();
    featureStore.setTransaction(transaction);
    try {
        featureStore.addFeatures(new DefaultFeatureCollection());
        transaction.commit();
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
    } finally {
        transaction.close();
    }
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:32,代码来源:OmsEpanetProjectFilesGenerator.java

示例8: testLockReleaseOfBulkAuthLock

import org.geotools.data.Transaction; //导入方法依赖的package包/类
@Test
public void testLockReleaseOfBulkAuthLock()
		throws InterruptedException,
		IOException {
	final LockingManagement memoryLockManager = new MemoryLockManager(
			"default");
	final Transaction t1 = Transaction.AUTO_COMMIT;
	final DefaultTransaction t2 = new DefaultTransaction();
	t2.addAuthorization("auth1");
	FeatureLock lock = new FeatureLock(
			"auth1",
			1 /* minute */);
	memoryLockManager.lockFeatureID(
			"sometime",
			"f4",
			t1,
			lock);
	memoryLockManager.lock(
			t2,
			"f4");
	t2.commit();
	// commit should not take away the lock
	assertTrue(memoryLockManager.exists("auth1"));
	memoryLockManager.release(
			"auth1",
			t1);
	assertFalse(memoryLockManager.exists("auth1"));
	t1.close();
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:30,代码来源:MemoryLockManagerTest.java

示例9: testTemporal

import org.geotools.data.Transaction; //导入方法依赖的package包/类
@Test
public void testTemporal()
		throws CQLException,
		IOException,
		ParseException {

	populate();
	final Transaction transaction2 = new DefaultTransaction();
	final Query query = new Query(
			"geostuff",
			CQL
					.toFilter("BBOX(geometry,44,27,42,30) and start during 2005-05-16T20:32:56Z/2005-05-20T21:32:56Z and end during 2005-05-18T20:32:56Z/2005-05-22T21:32:56Z"),
			new String[] {
				"geometry",
				"pid"
			});
	final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(
			query,
			transaction2);
	int c = 0;
	while (reader.hasNext()) {
		reader.next();
		c++;
	}
	reader.close();
	transaction2.commit();
	transaction2.close();
	assertEquals(
			2,
			c);

}
 
开发者ID:locationtech,项目名称:geowave,代码行数:33,代码来源:WFSTemporalQueryTest.java

示例10: exportGeometriesToShapeFile

import org.geotools.data.Transaction; //导入方法依赖的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();
    }

}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:76,代码来源:SimpleShapefile.java

示例11: exportToShapefileForceWGS84

import org.geotools.data.Transaction; //导入方法依赖的package包/类
public static void exportToShapefileForceWGS84(DataStore newDataStore, FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)/*,SimpleFeatureType ftype)*/ throws Exception {
 // carefully open an iterator and writer to process the results
    Transaction transaction = new DefaultTransaction();

    //CoordinateReferenceSystem crsOrig=featureCollection.getSchema().getCoordinateReferenceSystem();

    //set wgs84 coordinates ref sys
    SimpleFeatureType featureType = SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), DefaultGeographicCRS.WGS84);
    newDataStore.createSchema(featureType);

    FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriter(newDataStore.getTypeNames()[0],  transaction);
    //create the transformation
    MathTransform trans=CRS.findMathTransform(CRS.parseWKT(WKTString.WKT3995_ESRI),DefaultGeographicCRS.WGS84);


    FeatureIterator<SimpleFeature> iterator = featureCollection.features();
    try {

        while( iterator.hasNext() ){
            SimpleFeature feature = iterator.next();
            SimpleFeature copy = writer.next();


            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            geometry=JTS.transform(geometry,trans);


            if(geometry!=null){
            	copy.setDefaultGeometry( geometry.buffer(0));
            	writer.write();
            }else{
            	logger.warn("Warning:geometry null");
            }
        }
        transaction.commit();
        logger.info("Export to shapefile complete" );
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
        logger.error("Export to shapefile failed",problem );
    } finally {
        writer.close();
        iterator.close();
        transaction.close();
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:47,代码来源:SimpleShapefile.java

示例12: writeShapefile

import org.geotools.data.Transaction; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void writeShapefile(EnsembleDeLiens liens, String file) throws SchemaException, IOException {
  ShapefileDataStore store = new ShapefileDataStore(new File(file).toURI().toURL());
  String specs = "the_geom:LineString,linkId:Integer,edgeId:Integer,refId:Integer,compId:Integer,evalLink:Double,surfDist:Double,exact:Double,compl:Double"; //$NON-NLS-1$
  SimpleFeatureType type = DataUtilities.createType("Link", specs);
  store.createSchema(type);
  FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) store.getFeatureSource("Link");
  Transaction t = new DefaultTransaction();
  DefaultFeatureCollection collection = new DefaultFeatureCollection("coll",type);
  
  int linkId = 1;
  int edgeId = 1;
  GeometryFactory factory = new GeometryFactory();
  for (Lien feature : liens) {
    for (Arc edge : feature.getArcs()) {
      Lien l = (Lien) edge.getCorrespondant(0);
      List<Object> liste = new ArrayList<Object>(5);
      IFeature source = l.getObjetsRef().get(0);
      IFeature target = l.getObjetsComp().get(0);
      IDirectPosition sourcePosition = source.getGeom().centroid();
      IDirectPosition targetPosition = target.getGeom().centroid();
      liste.add(factory.createLineString(new Coordinate[]{new Coordinate(sourcePosition.getX(), sourcePosition.getY()), new Coordinate(targetPosition.getX(), targetPosition.getY())}));
      liste.add(new Integer(linkId));
      liste.add(new Integer(edgeId));
      liste.add(source.getAttribute("buildingId"));
      liste.add(target.getAttribute("buildingId"));
      liste.add(feature.getEvaluation());
      liste.add(feature.getDistanceSurfacique());
      liste.add(feature.getExactitude());
      liste.add(feature.getCompletude());
      SimpleFeature simpleFeature = SimpleFeatureBuilder.build(type, liste.toArray(), String
          .valueOf(edgeId++));
      collection.add(simpleFeature);
    }
    linkId++;
  }
  featureStore.addFeatures(collection);
  t.commit();
  t.close();
  store.dispose();
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:42,代码来源:AppariementSurfaces.java

示例13: setup

import org.geotools.data.Transaction; //导入方法依赖的package包/类
@Before
public void setup() throws SchemaException, CQLException, Exception {
    setupConf();
    try (final GeoWaveGeoIndexer indexer = new GeoWaveGeoIndexer()) {
        indexer.setConf(conf);
        dataStore = indexer.getGeoToolsDataStore();
        // Clear old data
        indexer.purge(conf);

        type = DataUtilities.createType(
                "GeoWaveFeatureReaderTest",
                "geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String");

        dataStore.createSchema(type);

        stime = DateUtilities.parseISO("2005-05-15T20:32:56Z");
        etime = DateUtilities.parseISO("2005-05-20T20:32:56Z");

        final Transaction transaction1 = new DefaultTransaction();
        final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(
                type.getTypeName(),
                transaction1);
        assertFalse(writer.hasNext());
        SimpleFeature newFeature = writer.next();
        newFeature.setAttribute(
                "pop",
                Long.valueOf(100));
        newFeature.setAttribute(
                "pid",
                "a" + UUID.randomUUID().toString());
        newFeature.setAttribute(
                "start",
                stime);
        newFeature.setAttribute(
                "end",
                etime);
        newFeature.setAttribute(
                "geometry",
                factory.createPoint(new Coordinate(27.25, 41.25)));
        fids.add(newFeature.getID());
        pids.add(newFeature.getAttribute("pid").toString());
        writer.write();
        newFeature = writer.next();
        newFeature.setAttribute(
                "pop",
                Long.valueOf(101));
        newFeature.setAttribute(
                "pid",
                "b" + UUID.randomUUID().toString());
        newFeature.setAttribute(
                "start",
                etime);
        newFeature.setAttribute(
                "geometry",
                factory.createPoint(new Coordinate(28.25, 41.25)));
        fids.add(newFeature.getID());
        pids.add(newFeature.getAttribute("pid").toString());
        writer.write();
        writer.close();
        transaction1.commit();
        transaction1.close();

        query = new Query(
                "GeoWaveFeatureReaderTest",
                ECQL.toFilter("IN ('" + fids.get(0) + "')"),
                new String[] {
                    "geometry",
                    "pid"
                });
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:72,代码来源:GeoWaveFeatureReaderTest.java

示例14: resetAnalysisLayer

import org.geotools.data.Transaction; //导入方法依赖的package包/类
/**
 * Reset analysis layer.
 *
 * @param allocationScenario
 *          the allocation scenario
 * @param featureStore
 * @throws WifInvalidInputException
 *           the wif invalid input exception
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
private boolean resetAnalysisLayer(
    final AllocationScenario allocationScenario,
    final SimpleFeatureStore featureStore) throws WifInvalidInputException,
IOException {
  final String uazDBTable = allocationScenario.getWifProject()
      .getSuitabilityConfig().getUnifiedAreaZone();
  final boolean status = true;
  final AllocationConfigs allocationConfig = allocationScenario
      .getAllocationConfig();
  // getting ready to update the data store
  LOGGER.debug("obtaining spatial information from: {}", uazDBTable);

  final Transaction transaction = new DefaultTransaction("update");
  try {
    final String[] allocationLabels = allocationConfig
        .getAllocationColumnsMap().values().toArray(new String[0]);
    for (final String value : allocationLabels) {
      LOGGER.debug("AllocationFFname to use: {}", value);
    }

    // Double[] resetValues = allocationConfig.getResetColumns();
    final String[] resetValues = allocationConfig.getResetColumnsStr();
    LOGGER.debug("Reset value is: {}", resetValues[0]);
    final Filter resetFilter = geodataFilterer.getResetFilter();

    // erasing the canvas of the allocation process in
    // database,it would be better if it was done before
    featureStore.modifyFeatures(allocationLabels, resetValues, resetFilter);
    LOGGER.info("About to reset the information for allocation... ");
    transaction.commit();
  } catch (final Exception e) {
    LOGGER
    .error(
        "resetAnalysisLayer rolling back to the last known modification, commit transaction failed: {}",
        e.getMessage());
    transaction.rollback();
    throw new WifInvalidInputException("Reset analysis layer failed", e);
  } finally {
    transaction.close();
    LOGGER
    .info(
        "Closing reset transaction, Finished resetting for Allocation Scenario label: {}",
        allocationScenario.getLabel());
  }
  return status;
}
 
开发者ID:AURIN,项目名称:online-whatif,代码行数:58,代码来源:AllocationAnalyzer.java

示例15: writeShapeFile

import org.geotools.data.Transaction; //导入方法依赖的package包/类
/**
 * Write a feature collection to a shape(.shp) file using the
 * standard GeoTools way of creating shape files. This function will
 * write the shape file using the Coordinate system WGS84.
 *
 * @param SimpleFeatureCollection collection The collection of features you wish to write to the shape file.
 * @param SimpleFeatureType TYPE The type object of the feature you wish to use.
 */
private static void writeShapeFile(SimpleFeatureCollection collection, SimpleFeatureType TYPE) throws IOException{

	//Prompt the user for a save location and filename.
	File newFile = getNewShapeFile();

	//Set up data store factory.
       ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();

       //Set up maps and parameters.
       Map<String, Serializable> params = new HashMap<String, Serializable>();
       params.put("url", newFile.toURI().toURL());
       params.put("create spatial index", Boolean.TRUE);

       //Set up data store.
       ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
       dataStore.createSchema(TYPE);

       //Set CRS.
       dataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
	
       //Create transaction.
       Transaction transaction = new DefaultTransaction("create");

       //Set up type name and feature source.
       String typeName = dataStore.getTypeNames()[0];
       SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);

       if(featureSource instanceof SimpleFeatureStore) {
           
       	//Set up feature store and attempt the transaction.
       	SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
           featureStore.setTransaction(transaction);
           try{
               featureStore.addFeatures(collection);
               transaction.commit();
           }catch (Exception e) {
               e.printStackTrace();
               transaction.rollback();
           }finally{
               transaction.close();
           }
       
       //If the type does not support read/write access.
       }else{
           System.out.println(typeName + " does not support read/write access");
       }
	
}
 
开发者ID:Stefangemfind,项目名称:MapMatching,代码行数:57,代码来源:App.java


注:本文中的org.geotools.data.Transaction.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。