From: Tommaso A. <tom...@gm...> - 2006-10-04 05:16:57
|
Hi, I'm trying to set a crs (ccordinate reference system) to the shapefiles I'm creating using geotools but it seems it doesn't have any effect; This is the code I'm using Any hint on how to set it ? ______________________________ protected CsShape createCsShape(CsPoint3DCollection punti) throws SchemaException, IllegalAttributeException, URISyntaxException, FactoryException, ClassNotFoundException { /** * Generazione sistema di coordinate */ // Cercare Proiezione Sistema coordinate geografico con proiezione di MonteMario Rome (sistema di Rif GaussBoaga) // Monte_Mario_Rome_Italy_2 CRSFactory crsFactory = FactoryFinder.getCRSFactory(null); String wkt = "PROJCS[\"UTM_Zone_10N\", " + "GEOGCS[\"WGS84\", " + "DATUM[\"WGS84\", " + "SPHEROID[\"WGS84\", 6378137.0, 298.257223563]], " + "PRIMEM[\"Greenwich\", 0.0], " + "UNIT[\"degree\",0.017453292519943295], " + "AXIS[\"Longitude\",EAST], " + "AXIS[\"Latitude\",NORTH]], " + "PROJECTION[\"Transverse_Mercator\"], " + "PARAMETER[\"semi_major\", 6378137.0], " + "PARAMETER[\"semi_minor\", 6356752.314245179], " + "PARAMETER[\"central_meridian\", -123.0], " + "PARAMETER[\"latitude_of_origin\", 0.0], " + "PARAMETER[\"scale_factor\", 0.9996], " + "PARAMETER[\"false_easting\", 500000.0], " + "PARAMETER[\"false_northing\", 0.0], " + "UNIT[\"metre\", 1.0], " + "AXIS[\"x\",EAST], " + "AXIS[\"y\",NORTH]]"; CoordinateReferenceSystem crs = crsFactory.createFromWKT(wkt); // qui lo assegna alla geometria (?) GeometryAttributeType geometryAttribute = (GeometryAttributeType) AttributeTypeFactory.newAttributeType("Geometry", Point.class, true, 0, null, crs); AttributeType[] attributiSHP = new AttributeType[strutturaDBF.length+1 ]; attributiSHP[0] = (GeometryAttributeType) AttributeTypeFactory.newAttributeType ("punto",Point.class,true,1,null,crs); for (int index = 0; index < strutturaDBF.length; index++) { attributiSHP[index + 1 ] = AttributeTypeFactory.newAttributeType(strutturaDBF[index][0], Class.forName(strutturaDBF[index][1])); } /** * Definizione del Feature */ FeatureType ftOggettoShp = FeatureTypeBuilder.newFeatureType(attributiSHP, type); /** * Definizione della geometria */ GeometryFactory geomFac = new GeometryFactory(); /** * Creazione di oggetti Point attraverso il vettore di coordinate di * punti Vettore di attributi */ Point[] myPoints = new Point[punti.size()]; String[][] myAttributi = new String[strutturaDBF.length][punti.size ()]; for (int i = 0; i < punti.size(); i++) { myPoints[i] = geomFac.createPoint(new Coordinate(Double .parseDouble(punti.get(i).get("X")), Double .parseDouble(punti.get(i).get("Y")), Double .parseDouble(punti.get(i).get("Z")))); for (int j = 0; j < strutturaDBF.length; j++) { myAttributi[j][i] = punti.get(i).get(strutturaDBF[j][2]); } } /** * Crezione di una feature con gli oggetti spaziali e dbf sulla base * della definizione fatta in precedenza */ Feature[] oggettoShpMulti = new Feature[ punti.size()]; FeatureCollection oggettiShp = (FeatureCollection) DefaultFeatureCollections.newCollection(); for (int i = 0; i < punti.size(); i++) { Object[] myOB = new Object[strutturaDBF.length + 1]; myOB[0] = myPoints[i]; for (int j = 0; j < strutturaDBF.length; j++) { myOB[j + 1] = myAttributi[j][i]; } oggettoShpMulti[i] = ftOggettoShp.create (myOB); oggettiShp.add(oggettoShpMulti[i]); } return new CsShape(ftOggettoShp, oggettiShp, this.type); } |