0
// 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)

The above code fails with:

java.io.IOException: Unable to write column value : double

I'm using scala version 2.10.4 and geotools version 11.2

Andrew Cassidy
  • 2,940
  • 1
  • 22
  • 46

1 Answers1

2

I used:

typeBuilder.add("value", classOf[java.lang.Double])

instead of

typeBuilder.add("value", classOf[Double])

classOf[java.lang.Double] // returns class java.lang.Double
classOf[Double] // returns double
java.lang.Double.TYPE // returns double

You need the class to be java.lang.Double

Andrew Cassidy
  • 2,940
  • 1
  • 22
  • 46
  • Just to clarify: `java.lang.Double` is also a class, and in fact `classOf[Double]` returns the Class object which corresponds to the Java `double` primitive (you can check this by doing `classOf[Double] == java.lang.Double.TYPE`). – Alexey Romanov Apr 22 '15 at 18:16
  • @AlexeyRomanov updated my answer since I was wrong about the primitive vs. class thing – Andrew Cassidy Apr 22 '15 at 20:04