Skip to content
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

Modularization of export code #341

Merged
merged 6 commits into from
Mar 16, 2019
Merged

Conversation

jywarren
Copy link
Member

Re: #298 just starting here!

@jywarren
Copy link
Member Author

@icarito @sashadev-sky take a look!

@jywarren
Copy link
Member Author

This is looking really good but there are a lot of warnings in the log, and a couple of the steps seem to have a "no directory found" error. But it can start to be pulled into a separate utility now! @icarito should we make a gem out of /lib/exporter.rb, called mapknitter?

@icarito
Copy link
Member

icarito commented Feb 17, 2019

Great! About the Gem, we ourselves don't have an immediate need as the container will likely continue to pull from git directly.

@jywarren
Copy link
Member Author

I guess i'm thinking of breaking this out as a separate Ruby library and independent repository so you don't have to include the whole MapKnitter container to use it, but we can start by just using this container, i guess. Can you try setting this up in a Google Cloud container so we can start trying to use it? Thanks!

@jywarren
Copy link
Member Author

Looking to resolve a few issues before merging:


gdalwarp -of GTiff -t_srs EPSG:4326 public/warps/saugus-landfill-incinerator/1-geo-unwarped.tif public/warps/saugus-landfill-incinerator/1-geo.tif
Output dataset public/warps/saugus-landfill-incinerator/1-geo.tif exists,
but some commandline options were provided indicating a new dataset
should be created.  Please delete existing dataset and run again.
- [#<BigDecimal:561a7ed604e0,'-0.1589606382 5039331034 5777777777 7777777777 7777777777 778E8',54(72)>, 10274177.588360637]
gdalwarp -te -71.3983854668 41.8351476452 -71.3916477578 41.840311368 public/warps/saugus-landfill-incinerator/1-geo.tif public/warps/saugus-landfill-incinerator/saugus-landfill-incinerator-geo.tif
Creating output file that is 1701P x 1304L.
Processing input file public/warps/saugus-landfill-incinerator/1-geo.tif.
Using band 4 of source image as alpha.
Using band 4 of destination image as alpha.
0...10...20...30...40...50...60...70...80...90...100 - done.
ERROR 6: EPSG PCS/GCS code 900913 not found in EPSG support files.  Is this a valid
EPSG coordinate system?
ERROR 6: No translation for an empty SRS to PROJ.4 format is known.
ERROR 6: No translation for an empty SRS to PROJ.4 format is known.
Traceback (most recent call last):
  File "/usr/bin/gdal2tiles.py", line 2262, in <module>
    gdal2tiles.process()
  File "/usr/bin/gdal2tiles.py", line 475, in process
    self.generate_metadata()
  File "/usr/bin/gdal2tiles.py", line 1123, in generate_metadata
    f.write( self.generate_tilemapresource())
  File "/usr/bin/gdal2tiles.py", line 1519, in generate_tilemapresource
    for z in range(self.tminz, self.tmaxz+1):
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
nice: cd: No such file or directory
nice: cd: No such file or directory
convert.im6: unable to access configure file `colors.xml' @ warning/configure.c/GetConfigureOptions/591.
convert.im6: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Unknown field with tag 34736 (0x87b0) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Unknown field with tag 34737 (0x87b1) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.

https://travis-ci.org/publiclab/mapknitter/builds/494340774#L2473

> generating tiles
ERROR 6: EPSG PCS/GCS code 900913 not found in EPSG support files.  Is this a valid
EPSG coordinate system?
ERROR 6: No translation for an empty SRS to PROJ.4 format is known.
ERROR 6: No translation for an empty SRS to PROJ.4 format is known.
Traceback (most recent call last):
  File "/usr/bin/gdal2tiles.py", line 2262, in <module>
    gdal2tiles.process()
  File "/usr/bin/gdal2tiles.py", line 475, in process
    self.generate_metadata()
  File "/usr/bin/gdal2tiles.py", line 1123, in generate_metadata
    f.write( self.generate_tilemapresource())
  File "/usr/bin/gdal2tiles.py", line 1519, in generate_tilemapresource
    for z in range(self.tminz, self.tmaxz+1):
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
> zipping tiles
nice: cd: No such file or directory
nice: cd: No such file or directory
> generating jpg
convert.im6: unable to access configure file `colors.xml' @ warning/configure.c/GetConfigureOptions/591.
convert.im6: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Unknown field with tag 34736 (0x87b0) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Unknown field with tag 34737 (0x87b1) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/768.

https://travis-ci.org/publiclab/mapknitter/builds/494340774#L2542

I'm going to look for the 900913 error first as it might have cascaded to cause the others.

@jywarren
Copy link
Member Author

So, i deleted the geotiff since we generate it twice in the tests.

Then i moved the 'delete directories' test to the end

I changed assert_not_nil to assert for a lot of assertions.

Finally, i added 3857 to try to bypass the 900913 error as per https://gis.stackexchange.com/questions/162767/gdal2tiles-py-gives-error-6-about-epsg900913-on-fresh-ubuntu-14-04-install

@jywarren
Copy link
Member Author

Hmm,


gdalwarp -te -s EPSG:3857 -71.3983854668 41.8351476452 -71.3916477578 41.840311368 public/warps/saugus-landfill-incinerator/1-geo.tif public/warps/saugus-landfill-incinerator/saugus-landfill-incinerator-geo.tif
Usage: gdalwarp [--help-general] [--formats]
    [-s_srs srs_def] [-t_srs srs_def] [-to "NAME=VALUE"]
    [-order n | -tps | -rpc | -geoloc] [-et err_threshold]
    [-refine_gcps tolerance [minimum_gcps]]
    [-te xmin ymin xmax ymax] [-tr xres yres] [-tap] [-ts width height]
    [-wo "NAME=VALUE"] [-ot Byte/Int16/...] [-wt Byte/Int16]
    [-srcnodata "value [value...]"] [-dstnodata "value [value...]"] -dstalpha
    [-r resampling_method] [-wm memory_in_mb] [-multi] [-q]
    [-cutline datasource] [-cl layer] [-cwhere expression]
    [-csql statement] [-cblend dist_in_pixels] [-crop_to_cutline]
    [-of format] [-co "NAME=VALUE"]* [-overwrite]
    [-nomd] [-cvmd meta_conflict_value]
    srcfile* dstfile
Available resampling methods:
    near (default), bilinear, cubic, cubicspline, lanczos, average, mode.
FAILURE: Unknown option name '-71.3916477578'

ah i see... hang on

@icarito
Copy link
Member

icarito commented Feb 20, 2019

Okay, I see. I'm building a container with gdal 2.4.0 from the Debian repositories for the Testing distribution "buster". I'll put the Dockerfile in a pull request here when it works. I'll be adding Ruby and ImageMagick. I see buster has Ruby 2.5.1 - hope this is fine? Otherwise I can downgrade to Stretch (current stable, with Ruby 2.3.3 and GDAL 2.1.2).

@icarito
Copy link
Member

icarito commented Feb 20, 2019

Okay I've built a container including GDAL, Imagemagick and Ruby, and pushed it to the Docker Hub.
That means you can run it right now by using docker run icarito/gdal_ruby_imagemagick:buster - it'll pull directly from the Docker Hub. I've also pushed it to GCE but now it needs an interface to interact with the world.

@jywarren this should be ready for integrating, check out with docker run icarito/gdal_ruby_imagemagick:buster to begin integration with the export.rb script!

Regards,
Sebastian

@jywarren
Copy link
Member Author

Thanks Sebastian - linking there now: #349 and I left some thoughts there too. Awesome!

@jywarren jywarren mentioned this pull request Feb 20, 2019
3 tasks
@jywarren
Copy link
Member Author

I believe everything but gdal2tiles.py is working and it just needed an API key, which I added.

@jywarren
Copy link
Member Author

Great, only a couple small things left:

Error: test_isolated_exporter_lib(ExporterTest): Errno::ENOENT: No such file or directory @ rb_sysopen - /app/public/system/images/2/original/test.png
================================================================================
.> calculating scale
> calculating scale
rm: cannot remove '/app/public/tms/saugus-landfill-incinerator': No such file or directory

@jywarren
Copy link
Member Author

:-( https://gis.stackexchange.com/questions/199915/unable-to-generate-tiles-using-gdal2tiles-py-for-a-single-band-gray-image

generating tiles
gdal2tiles.py -k --s_srs EPSG:3857 -t "saugus-landfill-incinerator" -g "AIzaSyAOLUQngEmJv0_zcG1xkGq-CXIPpLQY8iQ" /app/public/warps/saugus-landfill-incinerator/saugus-landfill-incinerator-geo.tif /app/public/tms/saugus-landfill-incinerator/
Traceback (most recent call last):
File "/usr/bin/gdal2tiles.py", line 2436, in
main()
File "/usr/bin/gdal2tiles.py", line 2433, in main
gdal2tiles.process()
File "/usr/bin/gdal2tiles.py", line 478, in process
self.generate_metadata()
File "/usr/bin/gdal2tiles.py", line 1155, in generate_metadata
f.write( self.generate_tilemapresource())
File "/usr/bin/gdal2tiles.py", line 1553, in generate_tilemapresource
for z in range(self.tminz, self.tmaxz+1):
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

@jywarren
Copy link
Member Author

I think this may have to do with the GDAL version; this is a post by me:

http://osgeo-org.1560.x6.nabble.com/gdal-dev-gdal2tiles-py-cannot-find-EPSG-900913-sees-only-GDAL-1-6-1-td3748343.html

@jywarren
Copy link
Member Author

I'm running GDAL 1.11.3, released 2015/09/16, on my local. Not sure what's in Travis though!

def self.generate_tiles(key, slug, root)
key = "AIzaSyAOLUQngEmJv0_zcG1xkGq-CXIPpLQY8iQ" if key == "" # ugh, let's clean this up!
key = key || "AIzaSyAOLUQngEmJv0_zcG1xkGq-CXIPpLQY8iQ"
gdal2tiles = 'gdal2tiles.py -k --s_srs EPSG:3857 -t "'+slug+'" -g "'+key+'" '+root+'/public/warps/'+slug+'/'+slug+'-geo.tif '+root+'/public/tms/'+slug+"/"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @icarito if you have a moment, i'm a bit stuck here; i think we're down to the GDAL version on this last command. I've been trying to run it locally.

Here are the files that this should be runnable on: https://publiclab.org/i/29584.zip

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gdal2tiles.py -k --s_srs EPSG:3857 -t "saugus-landfill-incinerator" -g "AIzaSyAOLUQngEmJv0_zcG1xkGq-CXIPpLQY8iQ" /app/public/warps/saugus-landfill-incinerator/saugus-landfill-incinerator-geo.tif /app/public/tms/saugus-landfill-incinerator/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And Mapknitter.org uses:

$ gdal2tiles.py --version
GDAL 2.1.2, released 2016/10/24

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis was same: GDAL 2.1.2, released 2016/10/24

@jywarren
Copy link
Member Author

@icarito would you mind trying to resolve the conflicts here?

jywarren and others added 6 commits March 16, 2019 15:08
* Try running Buster

* Include binary GDal

* Reorder Dockerfile

* Install npm

* Tweak apt command

* Update Dockerfile

* Simplfy

* Rollback ruby upgrade and rather install 2.4.4 from rvm

* Add login shell to support rvm

* Mysql deps

* Include git

* Fix entry command

* Move start command

* Revert "Fix entry command"

This reverts commit 1833f41.

* Remove entrypoint from Dockerfile

* Add -l parameter to bash

* More deps

* Bump mysql2 from 0.3.21 to 0.5.2

Bumps [mysql2](https://github.com/brianmario/mysql2) from 0.3.21 to 0.5.2.
- [Release notes](https://github.com/brianmario/mysql2/releases)
- [Changelog](https://github.com/brianmario/mysql2/blob/master/CHANGELOG.md)
- [Commits](brianmario/mysql2@0.3.21...0.5.2)

Signed-off-by: dependabot[bot] <[email protected]>

* activerecord-mysql2-adapter

* Return to mysql2 < 4 gem and add some grease

* Update exporter_test.rb

* Update exporter_test.rb

* Update exporter.rb

* Update exporter_test.rb
@jywarren
Copy link
Member Author

Linking to #341, and continuing here.

@jywarren jywarren merged commit 628b8b5 into publiclab:main Mar 16, 2019
@jywarren
Copy link
Member Author

@icarito this is complete!

@jywarren
Copy link
Member Author

I started working on a gem, but it's not all the way there. Still, closer to what we'd need for a completely externalized version of this! https://github.com/publiclab/mapknitter-exporter @icarito

@icarito
Copy link
Member

icarito commented Mar 17, 2019

Awesome I'll look at linking it to the Sinatra app for the API

@sashadev-sky
Copy link
Member

@jywarren when I run mapknitter locally with rake test my output is the same as one of your earlier travis builds posts here: https://travis-ci.org/publiclab/mapknitter/builds/494340774#L2542. (I get the errors about removing files that don't exist, gdal2tiles.py doesn't exist). I made changes locally to fix these problems then realized your most recent PR https://travis-ci.org/publiclab/mapknitter/builds/507274672?utm_source=github_status&utm_medium=notification didn't have them in the first place. Any idea why?

Wanted to make sure I understand this PR before looking at @icarito new export API

@icarito

@sashadev-sky
Copy link
Member

also am I remembering currently that the exports are supposed to export the images with the map background, not just the image overlays?

@jywarren
Copy link
Member Author

jywarren commented Mar 28, 2019 via email

@sashadev-sky
Copy link
Member

@jywarren hmm I don't know. Locally the tests wont pass if your root directory name has spaces in it, like for ex. on my computer I have the Mapknitter repo in a folder "Public Lab". Then it tries to run the commands 2 times: first on **/public then on lab/mapknitter/**. But if the root is https://mapknitter.org then it's fine.

To make it pass locally I just did root.gsub(" ", "\\ ") where appropriate. Would it make sense to add a PR with this change?

@jywarren
Copy link
Member Author

jywarren commented Mar 29, 2019 via email

@sashadev-sky
Copy link
Member

@jywarren would relative paths still work if the root is https://mapknitter.org? These could get more confusing because the files locally are nested at varied levels 3 or 4 levels deep

@jywarren
Copy link
Member Author

Hmm. Which PR didn't have them? I believe we were able to resolve them all by re-creating the directories in the tests at the right moments. Can you share your test changes? I do think relative paths may still work, like ../../ should work in URLs as well... see how https://mapknitter.org/maps/../maps/cranston-test just goes to https://mapknitter.org/maps/cranston-test?

@jywarren
Copy link
Member Author

But i just started making some changes to the extracted code here, that'll have to be refactored back in this repo once it stabilizes: publiclab/mapknitter-exporter#6

I am taking notes on the changes in publiclab/mapknitter-exporter#5 but I think you don't have to worry too much at this point... we're hoping to make all of that run itself externally.

@sashadev-sky
Copy link
Member

@jywarren I made changes to the code not the tests. Is it the tests I should have been changing?

chen-robert pushed a commit to chen-robert/mapknitter that referenced this pull request Dec 5, 2019
* starting to move things into exporter lib, parameterize

* additional mysql2 adapter change, sqlite compatibility

* moved almost all of exporter code into ruby lib

* Try to update GDAL from sources

* Update Dockerfile

* Try running Buster (publiclab#186)

* Try running Buster

* Include binary GDal

* Reorder Dockerfile

* Install npm

* Tweak apt command

* Update Dockerfile

* Simplfy

* Rollback ruby upgrade and rather install 2.4.4 from rvm

* Add login shell to support rvm

* Mysql deps

* Include git

* Fix entry command

* Move start command

* Revert "Fix entry command"

This reverts commit 1833f41.

* Remove entrypoint from Dockerfile

* Add -l parameter to bash

* More deps

* Bump mysql2 from 0.3.21 to 0.5.2

Bumps [mysql2](https://github.com/brianmario/mysql2) from 0.3.21 to 0.5.2.
- [Release notes](https://github.com/brianmario/mysql2/releases)
- [Changelog](https://github.com/brianmario/mysql2/blob/master/CHANGELOG.md)
- [Commits](brianmario/mysql2@0.3.21...0.5.2)

Signed-off-by: dependabot[bot] <[email protected]>

* activerecord-mysql2-adapter

* Return to mysql2 < 4 gem and add some grease

* Update exporter_test.rb

* Update exporter_test.rb

* Update exporter.rb

* Update exporter_test.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants