org.geoscript.feature

builder

package builder

Utilities for working with org.geoscript.feature.Feature in a typesafe way.

org.geoscript.feature.Feature is defined in terms of java.lang.Object and requires casting to use. The classes in this package provide some convenience around doing the casting - in particular, we define a trait Fields which can be used to retrieve and update fields from and to features.

A Fields may be constructed from a name and a type. The Fields then provides an unapply method for extracting values from features, and an update method for updating a feature (in place.) This enables pattern-matching with fields instances, and use of scala's syntactic sugar for updating collections. (By convention, fields instances should have names with an initial capital for use with pattern matching.)

val feature: Feature
val Title: Fields[String] = "title".of[String]
Title.unapply(feature): Option[String]
val Title(t) = feature
Title.update(feature, "Grand Poobah")
Title(feature) = "Grand Poobah"

Fields instances may be combined by use of the ~ operator. In this case, the primitive values used with the Field must also be combined or deconstructed using ~.

val Record: Fields[String ~ Int ~ String] =
  "title".of[String] ~ "releasedate".of[Int] ~ "artist".of[String]
val Record(title ~ releaseDate ~ artist) = feature
Record(feature) = ("The White Album" ~ 1968 ~ "The Beatles")

A Fields also provides the mkSchema method for creating a org.geoscript.feature.Schema. Since a Schema requires a name and any geometry fields must specify a org.geoscript.projection.Projection, these must be passed in to mkSchema.

val Place = "name".of[String] ~ "loc".of[Geometry]
val schema = Place.mkSchema("places", LatLon)

It is possible to create Features instead of modifying them. However, a Schema is required. The factoryForSchema method tests a schema for compatibility with a Fields and produces a feature factory function if the schema is compatible.

val placeSchema: Schema
Place.factoryForSchema(placeSchema) match {
  case Some(mkPlace) => mkPlace("Library" ~ Point(1,2))
  case None => sys.error("The datastore is not compatible with place features")
}

Finally, the schemaAndFactory method can be used to create a compatible schema and return it along with the feature factory. It takes the same inputs as the mkSchema method.

val (schema, mkPlace) = Place.schemaAndFactory("name", LatLon)
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. builder
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. implicit class Appendable[A] extends AnyRef

    Provides syntactic sugar for combining values into instances of the ~ class.

  2. implicit final class FieldSetBuilder extends AnyVal

    Provides syntactic sugar for creating Fields instances.

  3. sealed trait Fields[T] extends AnyRef

    A Fields represents one or more fields that features may have, and provides facilities for retrieving and updating those fields in features.

  4. case class ~[A, B](a: A, b: B) extends Product with Serializable

    A simple container for pairs of values, with nice syntax for destructuring nested pairs.

Inherited from AnyRef

Inherited from Any

Ungrouped