Created
September 24, 2011 19:52
-
-
Save dwins/1239777 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.geoscript._ | |
| import layer.Shapefile, support.math.Interpolation, style.combinators._, | |
| style.io.SLD, io.Sink | |
| import org.geotools.filter.text.ecql.ECQL.{ toFilter => cql } | |
| import java.awt.Color | |
| val states = Shapefile("geoscript/src/test/resources/data/states.shp") | |
| val buckets = | |
| (states.features.map(_.get[Double]("PERSONS")).toSeq | |
| .sorted | |
| .grouped(math.rint(states.count / 10d).toInt) | |
| .map(x => (x.head, x.last)) | |
| .toList) | |
| val intervals = (0 until buckets.size) map (_ / (buckets.size - 1d)) | |
| val colorAt = Interpolation.Linear(new Color(0, 0, 0x66), Color.RED) | |
| val widthAt = Interpolation.Linear(1d, 12d) | |
| val style = | |
| ( for ((i, (min, max)) <- intervals zip buckets) yield | |
| Stroke(stroke=colorAt(i), width=widthAt(i)).where( | |
| cql("POPULATION BETWEEN %f AND %f".format(min, max))) | |
| ) reduce (_ and _) | |
| SLD.write(style, Sink.stream(System.out)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment