Estou desenvolvendo um programa em java com netbeans, estou utilizando a biblioteca geotools, mas quando insiro o código <String, Serializable> Map params = new HashMap <String, Serializable> (); me surge um erro nesse comando e não estou conseguindo corrigir, esto usando o maven, será que estou esqucedo algum import?
Estou desenvolvendo um programa em java com netbeans, estou utilizando a biblioteca geotools, mas quando insiro o código <String, Serializable> Map params = new HashMap <String, Serializable> (); me surge um erro nesse comando e não estou conseguindo corrigir, esto usando o maven, será que estou esqucedo algum import?
Sem saber o erro específico fica difícil saber se o problema é alguma lib faltando…
Tenho um projeto que funciona e no meu maven:
packageorg.geotools.geotools;importjava.io.BufferedReader;importjava.io.File;importjava.io.FileReader;importjava.io.Serializable;importjava.util.Date;importjava.util.HashMap;importjava.util.Iterator;importjava.util.Map;importorg.geotools.data.DataUtilities;importorg.geotools.data.DefaultTransaction;importorg.geotools.data.Transaction;importorg.geotools.data.shapefile.ShapefileDataStore;importorg.geotools.data.shapefile.ShapefileDataStoreFactory;importorg.geotools.data.simple.SimpleFeatureCollection;importorg.geotools.data.simple.SimpleFeatureSource;importorg.geotools.data.simple.SimpleFeatureStore;importorg.geotools.feature.FeatureCollections;importorg.geotools.feature.simple.SimpleFeatureBuilder;importorg.geotools.feature.simple.SimpleFeatureTypeBuilder;importorg.geotools.geometry.jts.JTSFactoryFinder;importorg.geotools.referencing.crs.DefaultGeographicCRS;importorg.geotools.swing.data.JFileDataStoreChooser;importorg.opengis.feature.simple.SimpleFeature;importorg.opengis.feature.simple.SimpleFeatureType;//import org.opengis.*;importcom.vividsolutions.jts.geom.Coordinate;importcom.vividsolutions.jts.geom.GeometryFactory;importcom.vividsolutions.jts.geom.Point;/** * This example reads data for point locations and associated attributes from a comma separated text * (CSV) file and exports them as a new shapefile. It illustrates how to build a feature type. * <p> * Note: to keep things simple in the code below the input file should not have additional spaces or * tabs between fields. * * @source $URL: * http://svn.osgeo.org/geotools/branches/2.6.x/demo/example/src/main/java/org/geotools * /demo/Csv2Shape.java $ *//** * * @author USUARIO */publicclassCsv2Shape{publicstaticvoidmain(String[]args)throwsException{Filefile=JFileDataStoreChooser.showOpenFile("csv",null);if(file==null){return;}/* * We use the DataUtilities class to create a FeatureType that will describe the data in our * shapefile. * * See also the createFeatureType method below for another, more flexible approach. */finalSimpleFeatureTypeTYPE=(SimpleFeatureType)DataUtilities.createType("Location",// <- the name for our feature type"location:Point:srid=4326,"+// <- the geometry attribute: Point type"name:String"// <- a String attribute);/* * We create a FeatureCollection into which we will put each Feature created from a record * in the input csv data file */SimpleFeatureCollectioncollection=FeatureCollections.newCollection();/* * GeometryFactory will be used to create the geometry attribute of each feature (a Point * object for the location) */GeometryFactorygeometryFactory=JTSFactoryFinder.getGeometryFactory(null);SimpleFeatureBuilderfeatureBuilder=newSimpleFeatureBuilder(TYPE);BufferedReaderreader=newBufferedReader(newFileReader(file));try{/* First line of the data file is the header */Stringline=reader.readLine();System.out.println("Header: "+line);for(line=reader.readLine();line!=null;line=reader.readLine()){if(line.trim().length()>0){// skip blank linesStringtokens[]=line.split("\\,");doublelongitude=Double.parseDouble(tokens[0]);doublelatitude=Double.parseDouble(tokens[1]);Stringname=tokens[2].trim();/* Longitude (= x coord) first ! */Pointpoint=geometryFactory.createPoint(newCoordinate(longitude,latitude));featureBuilder.add(point);featureBuilder.add(name);SimpleFeaturefeature=featureBuilder.buildFeature(null);collection.add(feature);}}}finally{reader.close();}/* * Get an output file name and create the new shapefile */FilenewFile=getNewShapeFile(file);ShapefileDataStoreFactorydataStoreFactory=newShapefileDataStoreFactory();Map<String,Serializable>params=newHashMap<String,Serializable>();params.put("url",newFile.toURI().toURL());params.put("create spatial index",Boolean.TRUE);ShapefileDataStorenewDataStore=(ShapefileDataStore)dataStoreFactory.createNewDataStore(params);newDataStore.createSchema(TYPE);/* * You can comment out this line if you are using the createFeatureType * method (at end of class file) rather than DataUtilities.createType */newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);/* * Write the features to the shapefile */Transactiontransaction=newDefaultTransaction("create");StringtypeName=newDataStore.getTypeNames()[0];SimpleFeatureSourcefeatureSource=newDataStore.getFeatureSource(typeName);if(featureSourceinstanceofSimpleFeatureStore){SimpleFeatureStorefeatureStore=(SimpleFeatureStore)featureSource;featureStore.setTransaction(transaction);try{featureStore.addFeatures(collection);transaction.commit();}catch(Exceptionproblem){problem.printStackTrace();transaction.rollback();}finally{transaction.close();}System.exit(0);// success!}else{System.out.println(typeName+" does not support read/write access");System.exit(1);}}//* Prompt the user for the name and path to use for the output shapefile//*//* @param csvFile/* the input csv file used to create a default shapefile name * * @return name and path for the shapefile as a new File object */privatestaticFilegetNewShapeFile(FilecsvFile){Stringpath=csvFile.getAbsolutePath();StringnewPath=path.substring(0,path.length()-4)+".shp";JFileDataStoreChooserchooser=newJFileDataStoreChooser("shp");chooser.setDialogTitle("Save shapefile");chooser.setSelectedFile(newFile(newPath));intreturnVal=chooser.showSaveDialog(null);if(returnVal!=JFileDataStoreChooser.APPROVE_OPTION){// the user cancelled the dialogSystem.exit(0);}FilenewFile=chooser.getSelectedFile();if(newFile.equals(csvFile)){System.out.println("Error: cannot replace "+csvFile);System.exit(0);}returnnewFile;}}
doeslei formate o código dentro das tags [code] aqui no fórum.
Poste suas dúvidas no fórum apropriado também. Aqui é só para frameworks e bibliotecas brasileiros.
qual é o erro mesmo? o código não compila? é lançada uma exceção?
D
doeslei
Opa desculpe sou novo aqui.
O código não compila, na linha
Me acusa erro e não sei se está faltando alguma coisa no meu código (import) ou algum comando no maven.
Segue o erro: generics are not supported in source 1.3 (use -source 5 or higter to enable generics)
wpivotto
doeslei:
Opa desculpe sou novo aqui.
O código não compila, na linha
Me acusa erro e não sei se está faltando alguma coisa no meu código (import) ou algum comando no maven.
Segue o erro: generics are not supported in source 1.3 (use -source 5 or higter to enable generics)
você esta compilando pelo Maven?
O erro é claro, ele esta usando a versão 1.3 do java (default do maven), e essa versão não suporta generics (Map<String, Serializable>)