Giter Site home page Giter Site logo

Comments (5)

mattijn avatar mattijn commented on May 29, 2024 1

Thanks for sharing the file. There is nothing wrong with your data. Temporary solution: if you remove the Points from your geojson file it will be parsed correctly.

Bugs that I've to solve:
Multiple things are going wrong here regarding data collections containing Points.

  1. If there is a data collection that has a combination of Points and Polygons as such:
polygon_point = [
    {
        "type": "Polygon",
        "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]
    },
    {
        "type": "Point",
        "coordinates": [0.5, 0.5]
    }
]

Than the Extract class parses the Point type incorrectly into an arcs object containing the coordinate.

import topojson as tp
from topojson.core.extract import Extract

Extract(polygon_point)
Extract(
{'bookkeeping_geoms': [[0]],
 'linestrings': [<shapely.geometry.linestring.LineString object at 0x0000000008B5B588>],
 'objects': {0: {'arcs': [0], 'type': 'Polygon'},
             1: {'arcs': [0.5, 0.5], 'type': 'Point'}},
 'options': TopoOptions(
  {'prequantize': False,
 'presimplify': False,
 'simplify_algorithm': 'dp',
 'simplify_with': 'shapely',
 'topology': True,
 'topoquantize': False,
 'toposimplify': False,
 'winding_order': None}
),
 'type': 'Topology'}
)

The coordinates of type Point or Multipoint should remain as coordinates.

Otherwise you will hit indeed the following error:

tp.Topology(polygon_point)
c:\programdata\miniconda3\lib\site-packages\topojson\core\hashmap.py in resolve_bookkeeping(self, geoms)
    311         arcs = []
    312         for geom in geoms:
--> 313             arcs_in_geom = self.data["bookkeeping_geoms"][geom]
    314             for idx_arc, arc_ref in enumerate(arcs_in_geom):
    315                 arc_ids = self.data["bookkeeping_arcs"][arc_ref]

TypeError: list indices must be integers or slices, not float
  1. Moreover, if there is a data object containing only a Point as such:
point = [
    {
        "type": "Point",
        "coordinates": [0.5, 0.5]
    }
]

tp.Topology(point)

It cannot compute a bounding box since topojson currently only considers parsed linestrings:

c:\programdata\miniconda3\lib\site-packages\topojson\core\join.py in joiner(self, data)
    136 
    137             data["linestrings"], data["transform"] = quantize(
--> 138                 data["linestrings"], data["bbox"], quant_factor
    139             )
    140 

c:\programdata\miniconda3\lib\site-packages\topojson\ops.py in quantize(linestrings, bbox, quant_factor)
    403     """
    404 
--> 405     x0, y0, x1, y1 = bbox
    406 
    407     kx = 1 / ((quant_factor - 1) / (x1 - x0))

ValueError: not enough values to unpack (expected 4, got 0)
  1. This also means there is currently no delta-encoding of Points within topojson.

from topojson.

mattijn avatar mattijn commented on May 29, 2024

Thanks for filling this issue. Could you also share the GeoJSON that gives the errors?
Than I can have look

from topojson.

theluxaz avatar theluxaz commented on May 29, 2024

This is an example json feature collection with 4 features which i could not convert to any way to topojson. It is quite a complex polygon so sorry for hard to read file. Couldn't even convert each feature separately in any way.

I would be really grateful if you could show me a way how it could be acomplished, i'm sure it would be really useful for a lot of people in the future with similar problems :)

geojson show.zip

from topojson.

theluxaz avatar theluxaz commented on May 29, 2024

I see, Thank you very much for your detailed answer!!!
I will find a workaround for Points.

Wish you all the best.

from topojson.

mattijn avatar mattijn commented on May 29, 2024

Fixed by #62

from topojson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.