Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

[WIP] Make map-generator working again #1

Closed
wants to merge 8 commits into from
Closed

[WIP] Make map-generator working again #1

wants to merge 8 commits into from

Conversation

mneudert
Copy link
Member

@mneudert mneudert commented Aug 3, 2017

After a somewhat painful installation process of all required dependencies I managed to hack around enough to generate some maps:

https://gofile.io/?c=zQS7uf

Besides the changed remote archives and extracted files (@sgiehl seems to have a good looking fix in his fork) the data files itself seem to have changed quite a bit. Like the "ISO" field not always being available. Or missing "FIPS" data...

At the moment the "fix" is a total mess and I still need to check if the resulting files are actually usable in Piwik itself. The missing attributes (e.g. "data-fips") should be injectable by grabbing them from the existing files if the ISO codes are inserted correctly.

Not nice but perhaps it gets to a usable state until a better solution is available.

@sgiehl
Copy link
Member

sgiehl commented Aug 6, 2017

Had a short look. Seems the map generator didn't generate the same amount of maps... some are missing in the archive. Also Piwik seems not be able to handle the new maps. Needs some further investigation

@mneudert
Copy link
Member Author

mneudert commented Aug 6, 2017

The iso-data-attribute in the continent maps was wrong (data-iso-a3 instead of data-iso). With the most recent changes that is fixed and the maps are displayed and colored according to the visits.

Still up the check if countries are correct...

@sgiehl
Copy link
Member

sgiehl commented Aug 6, 2017

the world map wasn't included in the archive as well. Guess that needs to be activated here: https://github.com/piwik/piwik-map-generator/blob/master/make-maps.py#L38

@mneudert
Copy link
Member Author

mneudert commented Aug 6, 2017

World map should now be generated properly with the new datasets. At least it gets displayed and colored.

Country maps seem to not receive their attributes properly. They should have the necessary information (fips, fisp-, iso3, name, p) but at least France does not use them. The old maps triggered a data reload and the new ones don't...

@sgiehl
Copy link
Member

sgiehl commented Aug 7, 2017

There are still some maps missing after running the generator. Seems those fail with the message svg renderer doesn't know how to handle <class 'shapely.geometry.collection.GeometryCollection'>

@mneudert
Copy link
Member Author

mneudert commented Aug 7, 2017

Custom bounding boxes and patching around in the kartograph code allowed me to circumvent the GeometryCollection errors but not the no features found. The latter ones generate a custom part of the map but have no additional information like iso codes. Perhaps the bounding box is just placed wrong...

Patch for the GeometryCollection errors:

--- /usr/local/lib/python2.7/dist-packages/kartograph/renderer/svg.py	2017-08-07 18:49:15.881927526 +0000
+++ /usr/local/lib/python2.7/dist-packages/kartograph/renderer/svg.py	2017-08-07 18:48:55.841927406 +0000
@@ -96,10 +96,13 @@
         return node
 
     def _render_geometry(self, geometry):
-        from shapely.geometry import Polygon, MultiPolygon, LineString, MultiLineString, Point
+        from shapely.geometry import Polygon, MultiPolygon, LineString, MultiLineString, Point, GeometryCollection
         if geometry is None:
             return
-        if isinstance(geometry, (Polygon, MultiPolygon)):
+
+        if isinstance(geometry, (GeometryCollection)):
+            return
+        elif isinstance(geometry, (Polygon, MultiPolygon)):
             return self._render_polygon(geometry)
         elif isinstance(geometry, (LineString, MultiLineString)):
             return self._render_line(geometry)

I don't think there is a solution to the missing maps without patching kartograph or doing some other weird hacks. At least with my current knowledge.

@mneudert
Copy link
Member Author

mneudert commented Aug 7, 2017

Country maps are now clickable and properly load their data. Messed up the ISO data on the context layer...

@mneudert
Copy link
Member Author

As unhappy as I am to admit that I don't think I can get this to fully work. There are just some maps that (at least to my knowledge) I can't generate without patches to kartograph.py. And then there some maps that would require even more patches...

I have dabbled around with the successor library mapshaper and managed to generate what seems to be a full set of maps. But those are not compatible in any way with the current maps. For example I only know how to generate a map of a single country while currently all border countries are displayed and clickable.

The problem here:

  • Right now the maps are not complete! Zooming in to the region/city level of the United States makes Alaska disappear...
  • The new maps could include manual adjustments to those parts but that would probably require to drop displaying border countries...

Personally I think this generator here could be used to generate a final set of maps. However every map would require manual checking in the UI to verify it is not broken and "fits into the world" (some countries are not generated and some are new). Afterwards it would be best to find a new solution for the maps...

[ref: matomo-org/matomo/issues/11929]

@sgiehl
Copy link
Member

sgiehl commented Sep 25, 2017

Personally I think this generator here could be used to generate a final set of maps. However every map would require manual checking in the UI to verify it is not broken and "fits into the world" (some countries are not generated and some are new). Afterwards it would be best to find a new solution for the maps...

@mneudert Could you generate such a set of maps and create a PR for piwik with it?

@mneudert
Copy link
Member Author

Generating the maps is no problem.

Is there a simple way to generate at least one user for each possible region on the map to have everything nice and clickable to find the broken parts?

@sgiehl
Copy link
Member

sgiehl commented Sep 25, 2017

Not yet, but might be worth to implement in VisitorGenerator plugin

@Findus23
Copy link
Collaborator

I did take a look at the current status of the new maps to check if I can help, but I think the best solution is doing something completely else:

The great work of @mneudert shows that with hacking around it would be possible to get this repo back to running and create mostly working maps again.
But this would mean resurrecting a python library that hasn't been updated in 5 years (https://github.com/kartograph/kartograph.py) and a corresponding JavaScript library (https://github.com/kartograph/kartograph.js) that is even older. And as @gka who wrote both libraries also wrote all maps in Matomo it would mean rewriting a lot of code in all three parts just to get back the status quo (or rather the status from 6 years ago).

But most of this isn't needed anymore. As Gregor mentions in the README files of both repos, in the last 6 years many things changed and now there are many great alternatives:
mapshaper allows reading shapefiles, simplifying paths, converting the paths into many file formats.
There isn't really a need anymore to generate SVGs beforehand anymore as thanks to d3.js it should be far easier to render the geographic coordinates of the border polygons in the browser to SVGs.
That way it's probably also easier to add new features that depend on adding coordinates to the map in the future.
And the ideal data format for storing the maps would be topojson. It is a JSON format for storing geodata (in our case the coordinates of polygons) that is optimized for storing topological data (country borders). It has the advantage that lines between areas (arcs) are only stored once which allows smaller files and things like simplifying the border lines without getting empty space between countries.

@gka, what do you think is the best way to go about updating the maps in Matomo?

@sgiehl
Copy link
Member

sgiehl commented Sep 26, 2018

@Findus23 Likely we are going to build the maps completely new. Hope to be able to give a first preview or an update in a few weeks or so.

@tsteur
Copy link
Member

tsteur commented Jul 17, 2019

@mneudert @sgiehl @Findus23 i will close this PR for now. When it becomes a priority again we can look at it and reopen if needed.
In general for sure we would not want to rewrite / rebuild any map solution. We would either look to make this work as the map in general seems to be working well for us, it's just to get the map data in there and be able to update it in the future.

There are also some alternatives that could be interesting for us and support various features we need incl zoom levels etc. eg
https://github.com/Leaflet/Leaflet
https://github.com/openlayers/openlayers

@tsteur tsteur closed this Jul 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants