simplestmaps 1.5.0__tar.gz → 1.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: simplestmaps
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: Super simple on-liner maps in python.
5
5
  Home-page: http://github.com/fisadev/simplestmaps
6
6
  Author: Juan Pedro Fisanotti
@@ -49,7 +49,7 @@ Description: # Simplest Maps
49
49
 
50
50
  Here are a good set of examples that showcase (and document) all of the supported features:
51
51
 
52
- ## [Take a look at everything that's possible with so little code!](https://nbviewer.org/github/fisadev/simplestmaps/blob/59c84384463eb31eb827e2ec42cb40f2f502ff58/demo_and_docs.ipynb)
52
+ ## [Take a look at everything that's possible with so little code!](https://nbviewer.org/github/fisadev/simplestmaps/blob/e26f7cbe1eb195714f87e3804e766e302b7e51b5/demo_and_docs.ipynb)
53
53
 
54
54
  Platform: UNKNOWN
55
55
  Classifier: Intended Audience :: Developers
@@ -41,4 +41,4 @@ And every element plotted into the map is also customizable (colors, fonts, size
41
41
 
42
42
  Here are a good set of examples that showcase (and document) all of the supported features:
43
43
 
44
- ## [Take a look at everything that's possible with so little code!](https://nbviewer.org/github/fisadev/simplestmaps/blob/59c84384463eb31eb827e2ec42cb40f2f502ff58/demo_and_docs.ipynb)
44
+ ## [Take a look at everything that's possible with so little code!](https://nbviewer.org/github/fisadev/simplestmaps/blob/e26f7cbe1eb195714f87e3804e766e302b7e51b5/demo_and_docs.ipynb)
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
 
4
4
  setup(
5
5
  name="simplestmaps",
6
- version="1.5.0",
6
+ version="1.6.0",
7
7
  description="Super simple on-liner maps in python.",
8
8
  long_description=open("README.md").read(),
9
9
  long_description_content_type="text/markdown",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: simplestmaps
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: Super simple on-liner maps in python.
5
5
  Home-page: http://github.com/fisadev/simplestmaps
6
6
  Author: Juan Pedro Fisanotti
@@ -49,7 +49,7 @@ Description: # Simplest Maps
49
49
 
50
50
  Here are a good set of examples that showcase (and document) all of the supported features:
51
51
 
52
- ## [Take a look at everything that's possible with so little code!](https://nbviewer.org/github/fisadev/simplestmaps/blob/59c84384463eb31eb827e2ec42cb40f2f502ff58/demo_and_docs.ipynb)
52
+ ## [Take a look at everything that's possible with so little code!](https://nbviewer.org/github/fisadev/simplestmaps/blob/e26f7cbe1eb195714f87e3804e766e302b7e51b5/demo_and_docs.ipynb)
53
53
 
54
54
  Platform: UNKNOWN
55
55
  Classifier: Intended Audience :: Developers
@@ -24,20 +24,25 @@ def all_numbers(sequence):
24
24
  )
25
25
 
26
26
 
27
- def to_points(source):
27
+ def to_points(source, inverted_tuples=False):
28
28
  """
29
29
  Convert any possible thing to lat lon points and/or sequences of points.
30
+ Optionally reverse lat,lon values (used when converting points from lists of coordinates in
31
+ geojsons).
30
32
  """
31
33
  while source.__class__ in converters:
32
34
  # a custom type for which we have a converter registered, use it before trying to extract
33
35
  # points from it
34
36
  source = converters[source.__class__](source)
35
37
 
36
- if isinstance(source, GeneratorType):
38
+ if isinstance(source, Point):
39
+ # don't re-convert things that are already points
40
+ return source
41
+ elif isinstance(source, GeneratorType):
37
42
  # traverse the generator and build a tuple with its components, that we can inspect and
38
43
  # parse (so we can do things like decide how to parse it based on its length and the types
39
44
  # of its items)
40
- return to_points(tuple(source))
45
+ return to_points(tuple(source), inverted_tuples=inverted_tuples)
41
46
  elif hasattr(source, "lat") and hasattr(source, "lon"):
42
47
  # a few known classes that have lat long attributes
43
48
  lat, lon = source.lat, source.lon
@@ -53,14 +58,17 @@ def to_points(source):
53
58
  if len(source) == 1:
54
59
  # a sequence with a single object inside, so extract a point from it as if we just got
55
60
  # that object alone
56
- return to_points(source[0])
61
+ return to_points(source[0], inverted_tuples=inverted_tuples)
57
62
  elif len(source) in (2, 3) and all_numbers(source):
58
63
  # a sequence of 2 or 3 numbers, these must be coordinates, finally!
59
- lat, lon = source[:2]
64
+ if inverted_tuples:
65
+ lon, lat = source[:2]
66
+ else:
67
+ lat, lon = source[:2]
60
68
  else:
61
69
  # a sequence that doesn't look like coordinates but maybe a collection of points, try
62
70
  # to extract all of them into a list
63
- return [to_points(item) for item in source]
71
+ return [to_points(item, inverted_tuples=inverted_tuples) for item in source]
64
72
  else:
65
73
  raise ValueError(
66
74
  f"Can't guess the latitude and longitude from this object: {repr(source)}"
@@ -278,27 +286,21 @@ def geojson(path_or_data, points_as=marker, lines_as=line, areas_as=area):
278
286
  # a collection of features, extract them individually
279
287
  for feature in geojson_data["features"]:
280
288
  yield from geojson(feature["geometry"], points_as, lines_as, areas_as)
281
-
282
289
  elif geojson_type == "Point":
283
- # geojson uses lon,lat instead of lat,lon
284
- raw_coords = geojson_data["coordinates"]
285
- yield points_as(raw_coords[1], raw_coords[0])
286
-
290
+ yield points_as(
291
+ extract_single_points(to_points(geojson_data["coordinates"],
292
+ inverted_tuples=True))
293
+ )
287
294
  elif geojson_type == "LineString":
288
- # geojson uses lon,lat instead of lat,lon
289
- raw_coords_sequence = geojson_data["coordinates"]
290
295
  yield lines_as(
291
- (raw_coords[1], raw_coords[0])
292
- for raw_coords in raw_coords_sequence
296
+ extract_points_sequences(to_points(geojson_data["coordinates"],
297
+ inverted_tuples=True))
298
+ )
299
+ elif geojson_type in ("Polygon", "MultiPolygon"):
300
+ yield areas_as(
301
+ extract_points_sequences(to_points(geojson_data["coordinates"],
302
+ inverted_tuples=True))
293
303
  )
294
-
295
- elif geojson_type == "Polygon":
296
- # geojson uses lon,lat instead of lat,lon. And polygons have lists of lists of coords
297
- for raw_coords_sequence in geojson_data["coordinates"]:
298
- yield areas_as(
299
- (raw_coords[1], raw_coords[0])
300
- for raw_coords in raw_coords_sequence
301
- )
302
304
 
303
305
 
304
306
  def draw_map(*things, center=(0, 0), zoom=1.5, tiles="cartodbpositron"):
File without changes
File without changes