java - PRJ file not generated for null CoordinateReferenceSystem -
i trying create shape file the text file. used geotools library. can create shapefile, got warning coordinate system null, i'm setting!
the data in utm-wgs84-zone 30n. first, tried default coordinate system (wgs84), used epsg , decoded it. returns null.
public static void main(string[] args) throws exception { file[] files = getfiles("c://artcsvfiles//"); (int i=0;i<files.length;i++) { string outputfilepath = "c://art//" +files[i].getname()+".shp"; //string inputfilepath = "c://parktxtfiles//parkcluster0mp10dist0.005.csv"; string inputfilepath = files[i].getabsolutepath(); final simplefeaturetype type = datautilities.createtype("location", "location:point"); // see createfeaturetype(); featurecollection<simplefeaturetype, simplefeature> collection = featurecollections.newcollection(); bufferedreader reader = new bufferedreader(new filereader(files[i])); try { geometryfactory factory = jtsfactoryfinder.getgeometryfactory(null); (string line = reader.readline(); line != null; line = reader.readline()) { string split[] = line.split("\\,"); double longitude = double.parsedouble(split[0]); double latitude = double.parsedouble(split[1]); point point = factory.createpoint(new coordinate(longitude, latitude)); simplefeature feature = simplefeaturebuilder.build(type, new object[]{point}, null); collection.add(feature); } } { reader.close(); } file newfile = getnewshapefile(files[i], outputfilepath); datastorefactoryspi factory = new shapefiledatastorefactory(); map<string, serializable> create = new hashmap<string, serializable>(); create.put("url", newfile.touri().tourl()); create.put("create spatial index", boolean.true); shapefiledatastore newdatastore = (shapefiledatastore) factory.createnewdatastore(create); newdatastore.createschema(type); newdatastore.forceschemacrs(defaultgeographiccrs.wgs84); transaction transaction = new defaulttransaction("create"); string typename = newdatastore.gettypenames()[0]; featurestore<simplefeaturetype, simplefeature> featurestore; featurestore = (featurestore<simplefeaturetype, simplefeature>) newdatastore.getfeaturesource(typename); featurestore.settransaction(transaction); try { featurestore.addfeatures(collection); transaction.commit(); } catch (exception problem) { problem.printstacktrace(); transaction.rollback(); } { transaction.close(); } //system.exit(0); // exiting because use swing jfilechooser } } public static file[] getfiles(string args) { return new file(args).listfiles(); } private static file getnewshapefile(file file, string outputfilepath) { string path = file.getabsolutepath(); string newpath = path.substring(0,path.length()-4)+".shp"; file newfile = new file(outputfilepath); if( newfile.equals( file )){ system.out.println("cannot replace "+file); system.exit(0); } return newfile; } private static file getcsvfile(string[] args) throws filenotfoundexception { file file; if (args.length == 0){ jfilechooser chooser = new jfilechooser(); chooser.setdialogtitle("open csv file"); chooser.setfilefilter( new filefilter(){ public boolean accept( file f ) { return f.isdirectory() || f.getpath().endswith("csv") || f.getpath().endswith("csv"); } public string getdescription() { return "comma seperated value"; } }); int returnval = chooser.showopendialog( null ); if(returnval != jfilechooser.approve_option) { system.exit(0); } file = chooser.getselectedfile(); system.out.println("opening cvs file: " + file.getname()); } else { file = new file( args[0] ); } if (!file.exists()){ throw new filenotfoundexception( file.getabsolutepath() ); } return file; } /** * here how can use simplefeaturetype build create * schema shapefile dynamically. * <p> * method improvement on origional example * specifying defaultgeographiccrs.wgs84 , maximum field length. * <p> * @return simplefeaturetype */ static simplefeaturetype createfeaturetype() throws factoryexception { simplefeaturetypebuilder builder = new simplefeaturetypebuilder(); builder.setname( "location" ); coordinatereferencesystem crs = crs.decode("epsg:32630"); builder.setcrs(crs); //add attributes in order builder.add("location", point.class ); builder.length(15).add( "name", string.class ); system.out.println(builder.crs(crs)); //build type final simplefeaturetype location = builder.buildfeaturetype(); return location; } }
please change
final simplefeaturetype type = datautilities.createtype("location", "location:point");
to
final simplefeaturetype type = datautilities.createfeaturetype();
or pls change
final simplefeaturetype type = datautilities.createtype("location", "location:point");
to
final simplefeaturetype type = datautilities.createtype("location", "location:point:srid=4326," + "name:string," + "number:integer" );
and delete method createfeaturetype()
Comments
Post a Comment