Skip to content

Easy Importing for the Vector Package - #2885

Merged
echeipesh merged 1 commit into
locationtech:masterfrom
jbouffard:feature/easy-imports/vector
Apr 5, 2019
Merged

echeipesh merged 1 commit into
locationtech:masterfrom
jbouffard:feature/easy-imports/vector

Conversation

@jbouffard

@jbouffard jbouffard commented Mar 26, 2019 •

Copy link
Copy Markdown
Contributor

Overview

This PR simplifies the imports needed to use certain functionality in the geotrellis.vector package. Mainly, vector.io.wkb.Implicits, vector.io.wkt.implicits, and vector.io.json.Implicits are now all imported with import geotrellis.vector._.

Checklist

  • docs/CHANGELOG.rst updated, if necessary
  • docs guides update, if necessary
  • New user API has useful Scaladoc strings
  • Unit tests added for bug-fix or new feature

Demo

Before:

import geotrellis.vector._
import geotrellis.vector.io._
import geotrellis.vector.io.json.JsonFeatureCollection

val path: String = ???
val f = scala.io.Source.fromFile(path)
val collection = f.mkString.parseGeoJson[JsonFeatureCollection]

After:

import geotrellis.vector._
import geotrellis.vector.io.json.JsonFeatureCollection

val path: String = ???
val f = scala.io.Source.fromFile(path)
val collection = f.mkString.parseGeoJson[JsonFeatureCollection]

@jbouffard
jbouffard force-pushed the feature/easy-imports/vector branch from 1ef6cd7 to ecd235d Compare March 26, 2019 13:03
import geotrellis.vector.io.wkb.WKB
import geotrellis.vector.io.wkt.WKT

package object io extends io.json.Implicits

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These extensions have to be removed, because other wise if you do something like this:

import geotrellis.vector._
import geotrellis.vector.io._

The compiler will throw an error about not being able to find an implicit.

/** The algorithms herein are all implemented in JTS, but the wrapper methods
* here make it straightforward to call them with geotrellis.vector classes.
*/
implicit class withAnyGeometryMethods[G <: Geometry](val self: G) extends MethodExtensions[G]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this up just so it's easier to see what implicits will be in scope when importing geotrellis.vector._

@moradology

Copy link
Copy Markdown
Contributor

I'd personally like to see a wholesale renaming of io packages to something that won't make importing e.g. circe such a pain:
As of now, this doesn't work

import geotrellis.vector._
import io.circe._

Instead, this must be done:

import geotrellis.vector._
import _root_.io.circe._

@jbouffard

Copy link
Copy Markdown
Contributor Author

@moradology Is there an alternative name for vector.io package that you have? Maybe it could be serialize? Do you have any thoughts, @echeipesh?

@echeipesh

Copy link
Copy Markdown
Contributor

Not sure, formats sounds alright to me, serialize is a verb which is weird for package name. The argument also goes for other first tier packages that get imported all the time so: geotrellis.raster.io, geotrellis.spark.io. Those probably have things that can/should be split amongst multiple packages to avoid io.

I think that naming conflict is bad but I'd suggest dealing with that rename last or in different PR.

@echeipesh

echeipesh commented Mar 26, 2019 •

Copy link
Copy Markdown
Contributor

@jbouffard Part of the sugar in cats imports seems to be to bring important types to the root level with a type alias. Does anything in geotrellis.vector benefit from that ?

I know that I often end up reaching for WKB and WKT.

@jbouffard

Copy link
Copy Markdown
Contributor Author

@echeipesh That makes sense. I think the renaming is something we should probably discuss as a group. So I'll hold off on renaming until later.

Yeah, I think WKB and WKT would both benefit from being aliased. I'm not sure if there's anything that really needs to included in vector. All of the other types that aren't aliased are for pretty niche things.

@moradology

Copy link
Copy Markdown
Contributor

codec or serde perhaps

@jbouffard
jbouffard force-pushed the feature/easy-imports/vector branch from ba107a9 to 5de0eda Compare March 28, 2019 12:09
@jbouffard jbouffard mentioned this pull request Apr 3, 2019
1 task done
…mport in the vector package

Signed-off-by: Jacob Bouffard <[email protected]>

Cleaned up DissolveMethodsSpec

Signed-off-by: Jacob Bouffard <[email protected]>

Added the WKT and WKB vals to vector.package

Signed-off-by: Jacob Bouffard <[email protected]>

Fixed the imports in the code in the slick package

Signed-off-by: Jacob Bouffard <[email protected]>

Fixed the imports in the spark tests

Signed-off-by: Jacob Bouffard <[email protected]>

Removed WKT and WKB from the vector package

Signed-off-by: Jacob Bouffard <[email protected]>
@jbouffard
jbouffard force-pushed the feature/easy-imports/vector branch from f112577 to 14ea52f Compare April 5, 2019 17:36
@jbouffard
jbouffard changed the base branch from refactor/terse-imports to master April 5, 2019 17:37
@echeipesh
echeipesh merged commit a268657 into locationtech:master Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants