-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
not possible to create shapely object from wkt #463
Comments
These examples are not using WKT. http://toblerity.org/shapely/manual.html#well-known-formats They are using the geo_interface representation of the geometry, which is fine. The reason your polygon is failing is because it's not valid. Polygon coordinate sequences should be a list of lists of coordinates, not a list of coordinates as you have. This is because a polygon is composed of multiple linear rings - an exterior ring, and optional multiple interior rings. The following code works. Note the additional brackets in the coordinates.
Also note that if you're not using numpy arrays for the coordinates you could just as well use |
Okey, I misspelled the list, but either the correct form does not work:
even if I use numpy array:
|
@pythonfun0 Your polygon definition is not quite right. Try this: polygon = shape({'type': "Polygon", "coordinates": [[(0,0), (0,1), (1,1),(1,0),(0,0)]]}) Note the additional set of brackets around the coordinates. The structure for a GeoJSON
In other words: {
"type": "Polygon",
"coordinates": [
[<outer ring: (x, y), (x, y), ...>],
[<hole 1 ring: (x, y), (x, y), ...>],
[<hole 2 ring: (x, y), (x, y), ...>],
]
} but you don't have any holes, so you need:
Your |
If you read carefully my later comment, I wrote that it is not a nested list, I misspelled it! I don't want to create any nested polygon object! Please, paste a real working code example, if you can have it! Thanks! |
If you read carefully my later comment, I wrote that it is not a nested list, I misspelled it! it does not work with square brackets I don't want to create any nested polygon object! Please, paste a real working code example, if you can have it! Thanks! |
@pythonfun0 You're not seeing what we're trying to point out. You're typing this:
You should be typing this:
Even if your polygon only has an exterior ring and no interior rings, you still need to pass a nested list. |
I've already get it, sorry I read absently your answers. A list of list of coordinates works perfectly. |
Environment: Win10 64 bit
Version:
Creating shapely object from wkt is working in case of point and linestring
from shapely.geometry import asShape
but in case of polygon it fails. The object is seemingly created,
however calling any methods throwing exceptions
The text was updated successfully, but these errors were encountered: