/src/jvm/io/fsq/twofishes/indexer/util/ShapefileWriter.scala

https://github.com/foursquare/fsqio · Scala · 107 lines · 0 code · 19 blank · 88 comment · 0 complexity · 020c124a11c3fac84a737456ddb643f0 MD5 · raw file

  1. // TODO: This file seems unused and has terrible deps for this package. Delete?
  2. // package io.fsq.twofishes.indexer.util
  3. // import io.fsq.twofishes.indexer.mongo.MongoGeocodeDAO
  4. // import com.mongodb.casbah.Imports._
  5. // import salat._
  6. // import salat.annotations._
  7. // import salat.dao._
  8. // import salat.global._
  9. // import com.vividsolutions.jts.geom.{GeometryFactory, MultiPolygon, Polygon}
  10. // import com.vividsolutions.jts.io.WKBReader
  11. // import java.io.File
  12. // import org.geotools.data.{DataUtilities, DefaultTransaction}
  13. // import org.geotools.data.collection.ListFeatureCollection
  14. // import org.geotools.data.shapefile.{ShapefileDataStore, ShapefileDataStoreFactory}
  15. // import org.geotools.data.simple.{SimpleFeatureCollection, SimpleFeatureStore}
  16. // import org.geotools.feature.simple.SimpleFeatureBuilder
  17. // import org.geotools.referencing.crs.DefaultGeographicCRS
  18. // import org.opengis.feature.simple.SimpleFeatureType
  19. // import scala.collection.JavaConverters._
  20. // object BuildPolygonShapefile {
  21. // val TYPE: SimpleFeatureType = DataUtilities.createType("Location",
  22. // "location:MultiPolygon:srid=4326," + // <- the geometry attribute: Point type
  23. // "id:String" // <- a String attribute
  24. // )
  25. // def buildAndWriteCollection(filename: String) {
  26. // writeCollection(buildCollection(), filename)
  27. // }
  28. // def writeCollection(collection: SimpleFeatureCollection, filename: String) {
  29. // val newFile = new File(filename);
  30. // val storeFactory = new ShapefileDataStoreFactory()
  31. // val create = Map( "url" -> newFile.toURI.toURL)
  32. // val newDataStore = storeFactory.createNewDataStore(create.asJava).asInstanceOf[ShapefileDataStore]
  33. // newDataStore.createSchema(TYPE)
  34. // /*
  35. // * You can comment out this line if you are using the createFeatureType method (at end of
  36. // * class file) rather than DataUtilities.createType
  37. // */
  38. // newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
  39. // val transaction = new DefaultTransaction("create");
  40. // val typeName = newDataStore.getTypeNames()(0)
  41. // val featureSource = newDataStore.getFeatureSource(typeName)
  42. // if (featureSource.isInstanceOf[SimpleFeatureStore]) {
  43. // val featureStore = featureSource.asInstanceOf[SimpleFeatureStore]
  44. // featureStore.setTransaction(transaction);
  45. // try {
  46. // featureStore.addFeatures(collection);
  47. // transaction.commit();
  48. // } catch {
  49. // case problem: Throwable => {
  50. // problem.printStackTrace();
  51. // transaction.rollback();
  52. // }
  53. // } finally {
  54. // transaction.close();
  55. // }
  56. // } else {
  57. // System.out.println(typeName + " does not support read/write access");
  58. // }
  59. // }
  60. // def buildCollection(): SimpleFeatureCollection = {
  61. // val featureBuilder = new SimpleFeatureBuilder(TYPE)
  62. // val collection = new ListFeatureCollection(TYPE)
  63. // val total = MongoGeocodeDAO.count(MongoDBObject("hasPoly" -> true))
  64. // val records =
  65. // MongoGeocodeDAO.find(MongoDBObject("hasPoly" -> true))
  66. // val geomFactory = new GeometryFactory()
  67. // val wkbReader = new WKBReader()
  68. // for {
  69. // (record, index) <- records.zipWithIndex
  70. // if (record.woeType != YahooWoeType.ADMIN2)
  71. // polygon <- record.polygon
  72. // } {
  73. // val geom = wkbReader.read(polygon)
  74. // var multiPolygon = geom
  75. // if (geom.isInstanceOf[Polygon]) {
  76. // multiPolygon = new MultiPolygon(Array(geom.asInstanceOf[Polygon]), geomFactory)
  77. // }
  78. // if (index % 10000 == 0) {
  79. // println("outputted %d of %d (%.2f%%)".format(index, total, index*100.0/total))
  80. // }
  81. // featureBuilder.add(multiPolygon)
  82. // featureBuilder.add(record.toGeocodeServingFeature.feature.longId + "," + record._woeType.toString)
  83. // val feature = featureBuilder.buildFeature(null)
  84. // collection.add(feature)
  85. // }
  86. // collection
  87. // }
  88. // }