AnsweredAssumed Answered

how can i set decimal precision at the time shapefile creation via java code

Question asked by amb_2002 on Sep 19, 2014

my code is mention below in the below i can create i shape file with numeric/long and string type, but i am not able to set the decimal precision in specific column. e.g.  for RELPOS field i need to store the value in xxx.xxx (in 3 decimal value). how can create decimal value type via java code.

 

 

 

private static SimpleFeatureType createFeatureType() throws FactoryException {

 

 

SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName("Location");

 

 

String wkt =  "GEOGCS[" + "\"GCS_WGS_1984\"," + "  DATUM[" + "    \"D_WGS_1984\","
+ "    SPHEROID[\"WGS_1984\",6378137,298.257223563]],"
+ "  PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],"
+ "  UNIT[\"Degree\",0.017453292519943295,AUTHORITY[\"EPSG\",\"9122\"]],"
+ "  AXIS[\"Lat\",NORTH]," + "  AXIS[\"Long\",EAST],"
+ "  AUTHORITY[\"EPSG\",\"4326\"]]";

 

 

 

 

CoordinateReferenceSystem crs = CRS.parseWKT(wkt);     
System.setProperty("org.geotools.referencing.forceXY", "true");
builder.setCRS(crs);

 

 

// add attributes in order
builder.add("the_geom", Point.class);

 

 

builder.length(15).add("ID", Long.class);
builder.length(4).add("FEATTYP",Integer.class);
builder.length(1).add("IMPORT",Integer.class);
builder.length(3).add("ARNAMELC",String.class);
builder.length(240).add("NAME",String.class);
builder.length(150).add("STNAME",String.class);
builder.length(3).add("STNAMELC",String.class);
builder.length(15).add("HSNUM",String.class);////but house number is lengthy in Japan database which is more than 15.
builder.length(10).add("POSTCODE",String.class);
builder.length(15).add("MUNID",Long.class);
builder.length(11).add("MUNCD",String.class);
builder.length(100).add("MUNNAME",String.class);
builder.length(100).add("BUANAME",String.class);
builder.length(25).add("TELNUM",String.class);
builder.length(25).add("FAXNUM",String.class);
builder.length(70).add("EMAIL",String.class);
builder.length(150).add("HTTP",String.class);////changed to 150 not clear in multinet document
builder.length(70).add("COMPNAME",String.class);//changed from 150 to 70
builder.length(15).add("CLTRPELID",Long.class);
builder.length(6).add("RELPOS",Integer.class);
builder.length(50).add("EXTPOIID",String.class);
builder.length(15).add("ADDRPID",Long.class);
builder.length(7).add("SUBCAT",Long.class);
builder.length(2).add("GAL",Integer.class);
builder.length(1).add("POSACCUR",Integer.class);
// build the type
final SimpleFeatureType LOCATION = builder.buildFeatureType();
return LOCATION;
}

Outcomes