// My type
val typeBuilder = new SimpleFeatureTypeBuilder()
typeBuilder.setName("line-query-seg")
typeBuilder.add("value", classOf[Double])
typeBuilder.setDefaultGeometry("the_geom")
typeBuilder.add("the_geom", classOf[LineString])
val sft = typeBuilder.buildFeatureType()
// Trying to create a shapefile of this type
val dataStoreFactory = new ShapefileDataStoreFactory()
val shp = new File("/tmp/collection.shp")
val params = scala.collection.Map[String, Serializable]("url" -> shp.toURI.toURL,
"create spatial index" -> true
)
val shpDS = dataStoreFactory.createNewDataStore(params.asJava).asInstanceOf[ShapefileDataStore]
shpDS.createSchema(sft)
以上代码失败:
java.io.IOException:无法写入列值:double
我使用的是scala版本2.10.4和geotools版本11.2
答案 0 :(得分:2)
我用过:
typeBuilder.add("value", classOf[java.lang.Double])
而不是
typeBuilder.add("value", classOf[Double])
classOf[java.lang.Double] // returns class java.lang.Double
classOf[Double] // returns double
java.lang.Double.TYPE // returns double
您需要该类为java.lang.Double