Giter Site home page Giter Site logo

topojson.py's Introduction

TOPOJSON.PY

Port of topojson more of a translation then a port at this point, licensed under same BSD license as original, current usage:

input can be a file-like object, a path to a file, or a dict, output can be a path or a file-like object, if omited a dict is returned

current tested options are quantization and simplify.

from topojson import topojson
#give it a path in and out
topojson(inPath,outPath, quantization=1e6, simplify=0.0001)

can also go the other way.

from topojson import geojson
geojson(topojson,input_name=None,out_geojson=None)

topojson may be a dict, a path, or a file like object, input_name is a string and if omited the first object in topojson.objects is used, geojson may be a file like object or a path if omitied the dict is returned

known issues:

  • coding style only a mother could love
  • holds everything in memory, this could be bad
  • should be able to incrementally add features to a topojson object

topojson.py's People

Contributors

calvinmetcalf avatar casyfill avatar cmc333333 avatar jsheedy avatar pangstar avatar scw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

topojson.py's Issues

Converting code to idiomatic Python

Nice work, man! I was looking for the quantization algorithm (Mike's source is way beyond my javascript wizardry level).

The code still smells like javascript. :-)

I want to help converting this to more idiomatic Python, can I send PR's?

ERROR installing locally

Hi!!

Cannot install via pip install -e .

FileNotFoundError: [Errno 2] No such file or directory: '/srv/TESTS/topojson.py/pdvega/__init__.py'

that comes from where:

VERSION = version('pdvega/__init__.py')

Am I using the wrong branch (master)?
Or the correct line is :

VERSION = version('topojson/__init__.py')

After change it, the installation is successful but the version number is :

topojson 0.1.1.dev0

no clue if it is the intended version

Thanks cheers

is_point

@scardine your function

def is_point(p):
    try:
        float(p[0]), float(p[1])
    except (TypeError, IndexError):
        return False

is not equivalent to

is_point = lambda x : type(x)==type([]) and len(x)==2

lines equal

these two functions end up not being equivalent as when the latter is used something t that is not iterable gets through p and not lines_equal(p,t)

def lines_equal(a, b):
    if not (type(a) == type(b) == type([])):
        return True
    n = len(a)
    i = 0
    if len(b) != n:
        return False
    while i < n:
        if a[i] != b[i]:
            return False
        i += 1
    return True

and

def lines_equal(a, b):
    for arg in (a, b):
        if not isinstance(arg, list):
            return False
    return a == b

fix geojson package clash

Great piece of work!

I have currently sub moduled this repo however I am getting a package clash. Could you add "." when referencing internal folders in your "from" statements.

specifically for geojson in the root init.py (making it from .geojson import geojson)
geojson/init.py (making it from .conversion import conversion)
geojson/conversion.py (making it from .geojson import from_topo)

Thanks!

Change the format of the input data

as it is said #30 we need to change structure of the input data in order to use the topojson method, it will be nice that this data had the same format as the geopandas provides

abandoned?

Sorry to bother, but noticed there were no PR merged in a long period of time. Is it on purpose or this repo is, generally, abandoned? I am asking as I use it rather heavily for my data transformations,

also trying to convince maintainers to include it as optionald dependency for geojson, here. Do you mind if I'll try to make it pip-installable?

Best,
Philipp

Status of this library?

I'm looking for ways to add d3 export to qgis2web:

qgis2web/qgis2web#171

This library could be an essential part, to generate the topoJSON from QGIS's exported geoJson. Is this library stable and functional?

remove reliance on pdvega

It looks like it relies on an install of pdvega to generate a VERSION number in setup.py.
It would be nice to remove that if possible.
Thanks,
Pat.

issue with converting points

I'm trying to use topojson.py to convert a geojson to topojson. The geojson was made with geopandas โ€” originally the points were shapely point objects. My geojson looks like this:

"type": "Feature", "properties": { }, "geometry": { "type": "Point", 
"coordinates": [ 62.269649605592754, 32.429278041035452 ] } }

and I get the following error when trying to convert:

~/anaconda3/lib/python3.6/site-packages/topojson/mytypes.py in 
Point(self, point)
     35             self.polygon(coordinate);
     36     def Point(self,point):
---> 37         self.point(point['coordinates'])
     38     def Polygon(self,polygon):
     39         self.polygon(polygon['coordinates'])
TypeError: point() takes 1 positional argument but 2 were given

I'm calling topojson like so:

topojson("points.json", "pointstopo.json", quantization=1e6, simplify=0.0001) 

I can't understand what I'm doing wrong, so I'm wondering if this is a bug/if there is some sort of larger incompatibility going on.

(Also, thanks for your work developing this package!)

flake8 highlights multiple issues

below:

./__init__.py:1:1: F401 'topojson.topojson' imported but unused
./__init__.py:2:1: F401 '.geojson.geojson' imported but unused
./__init__.py:2:29: W292 no newline at end of file
./setup.py:15:80: E501 line too long (88 > 79 characters)
./topojson/simplify.py:79:80: E501 line too long (85 > 79 characters)
./topojson/simplify.py:133:26: W601 .has_key() is deprecated, use 'in'
./topojson/simplify.py:135:31: F821 undefined name 'geometry'
./topojson/clockwise.py:20:80: E501 line too long (80 > 79 characters)
./topojson/coordinatesystems.py:32:9: E731 do not assign a lambda expression, use a def
./topojson/coordinatesystems.py:41:80: E501 line too long (81 > 79 characters)
./topojson/coordinatesystems.py:42:80: E501 line too long (83 > 79 characters)
./topojson/coordinatesystems.py:62:80: E501 line too long (80 > 79 characters)
./topojson/coordinatesystems.py:78:80: E501 line too long (84 > 79 characters)
./topojson/coordinatesystems.py:79:80: E501 line too long (83 > 79 characters)
./topojson/coordinatesystems.py:80:80: E501 line too long (81 > 79 characters)
./topojson/coordinatesystems.py:100:80: E501 line too long (93 > 79 characters)
./topojson/coordinatesystems.py:106:80: E501 line too long (86 > 79 characters)
./topojson/coordinatesystems.py:130:80: E501 line too long (85 > 79 characters)
./topojson/line.py:45:80: E501 line too long (83 > 79 characters)
./topojson/line.py:90:43: E721 do not compare types, use 'isinstance()'
./topojson/conversion.py:18:80: E501 line too long (85 > 79 characters)
./topojson/__init__.py:1:1: F401 '.conversion.convert as topojson' imported but unused
./topojson/utils.py:11:1: E731 do not assign a lambda expression, use a def
./topojson/mytypes.py:52:16: E711 comparison to None should be 'if cond is None:'
./topojson/mytypes.py:67:26: E711 comparison to None should be 'if cond is not None:'
./topojson/topology.py:8:1: F401 '.clockwise.Clock' imported but unused
./topojson/topology.py:9:1: F401 'decimal.Decimal' imported but unused
./topojson/topology.py:29:5: E731 do not assign a lambda expression, use a def
./topojson/topology.py:85:5: F841 local variable 'emax' is assigned to but never used
./topojson/topology.py:87:5: E301 expected 1 blank line, found 0
./topojson/topology.py:91:20: E713 test for membership should be 'not in'
./topojson/topology.py:94:5: F841 local variable 'fcInst' is assigned to but never used
./topojson/topology.py:95:5: E731 do not assign a lambda expression, use a def
./topojson/topology.py:97:5: E301 expected 1 blank line, found 0
./topojson/topology.py:100:36: E711 comparison to None should be 'if cond is None:'
./topojson/topology.py:110:80: E501 line too long (86 > 79 characters)
./topojson/topology.py:120:80: E501 line too long (82 > 79 characters)
./topojson/topology.py:134:25: E711 comparison to None should be 'if cond is None:'
./topojson/topology.py:139:31: E711 comparison to None should be 'if cond is None:'
./topojson/topology.py:146:80: E501 line too long (80 > 79 characters)
./topojson/stitchpoles.py:7:22: E721 do not compare types, use 'isinstance()'
./topojson/stitchpoles.py:8:9: F841 local variable 'verbose' is assigned to but never used
./topojson/hashtable.py:9:24: E721 do not compare types, use 'isinstance()'
./topojson/geojson/conversion.py:8:60: F821 undefined name 'unicode'
./topojson/geojson/conversion.py:12:31: F821 undefined name 'file'
./topojson/geojson/conversion.py:17:56: F821 undefined name 'unicode'
./topojson/geojson/conversion.py:20:30: F821 undefined name 'file'
./topojson/geojson/geojson.py:92:63: F821 undefined name 'coordinates'
./topojson/geojson/geojson.py:96:73: F821 undefined name 'coordinates'
./topojson/geojson/geojson.py:96:80: E501 line too long (86 > 79 characters)
./topojson/geojson/geojson.py:110:80: E501 line too long (84 > 79 characters)
./topojson/tests/topojson_test.py:14:80: E501 line too long (112 > 79 characters)
./topojson/tests/topojson_test.py:20:80: E501 line too long (80 > 79 characters)

Bug?

Just cloned your repo and tried the following:

>>> from topojson import topojson
>>> g = {'type': 'GeometryCollection', 'features': [{'geometry': {'type': 'LineString', 'properties': {}, 'coordinates': [[4920, 9999], [0, 142], [9999, 0]], 'arcs': [0]}, 'type': 'Feature', 'properties': {}}]}
>>> topojson(g, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "topojson/topojson/conversion.py", line 19, in convert
    output_dict = topology(input_dict, *args, **kwargs)
  File "topojson/topojson/topology.py", line 24, in topology
    system.name =systems["cartesian"]
AttributeError: 'bool' object has no attribute 'name'

Python 3 compatibility

My application requires Python 3, so I did a quick fix to make it run and created a pull request. The included test runs under Python 2.7.10 and Python 3.4.3.

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.