How do I divide a very large OpenStreetMap file into smaller files in R without running out of memory?

Max Candocia

I am currently looking to have map files that are no larger than the sizes of municipalities in Mexico (at largest, about 3 degrees longitude/latitude across). However, I have been running into memory issues (at the very least) when trying to do so. The file size of the OSM XML object is 1.9 GB, for reference.

library(osmar)
get.map.for.municipality<-function(province,municipality){
  base.map.filename = 'OpenStreetMap/mexico-latest.osm'
  #bounds.list is a list that contains the boundaries
  bounds = bounds.list[[paste0(province,'*',municipality)]]
  my.bbox = corner_bbox(bounds[1],bounds[2],bounds[3],bounds[4])
  my.map.source = osmsource_file(base.map.filename)
  my.map = get_osm(my.bbox,my.map.source)
  return(my.map)
}

I am running this inside of a loop, but it can't even get past the first one. When I tried running it, my computer froze and I was only able to take a screenshot with my phone. The memory steadily inclined over the course of a few minutes, and then it shot up really quickly, and I was unable to react before my computer froze.

What is a better way of doing this? I expect to have to run this loop about 100-150 times, so any way that is more efficient in terms of memory would help. I would prefer not to download smaller files from an API service. If necessary, I would be willing to use another programming language (preferably Python or C++), but I prefer to keep this in R.

enter image description here

defvol

I'd suggest not use R for that.

There are better tools for that job. Many ways to split, filter stuff from the command line or using a DBMS.

Here are some alternatives extracted from the OSM Wiki http://wiki.openstreetmap.org:

Filter your osm files using osmfilter: "osmfilter is used to filter OpenStreetMap data files for specific tags. You can define different kinds of filters to get OSM objects (i.e. nodes, ways, relations), including their dependent objects, e.g. nodes of ways, ways of relations, relations of other relations."

Clipping based on Polygons or borders using osmconvert: http://wiki.openstreetmap.org/wiki/Osmconvert#Applying_Geographical_Borders

You can write bash scripts for both osmfilter and osmconvert, but I'd recommend using a DBMS. Just import into PostGIS using osm2pgsql, and connect your R code with any Postgresql driver. This will optimize your read/write ops.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Read/download large file in PHP without running out of memory

From Dev

How to iterate a large table in Django without running out of memory?

From Java

Calculate a large amount without running out of memory

From Java

How do I process very large file (13GB) in python without crashing?

From Dev

How can I read tsv files and store them as hdf5 without running out of memory?

From Dev

How do I make a puzzle app in droid without running out of memory?

From Dev

How do I split a large sql databse backup file into smaller parts without messing up with the backed up queries?

From Dev

How to output a massive file with PHP without running out of memory

From Dev

How do I append a line to the beginning of a very large file in Linux?

From Dev

How do I search through a very large csv file?

From Dev

Cordova calculate sha1 hash of large file without running out of memory

From Dev

How do I suppress "low memory" warnings in Vista Home Premium when running without paging file?

From Dev

Bash script using gzip and bcftools running out of memory with large files

From Dev

Break large file into smaller files

From Dev

Can I split a large HAProxy config file into multiple smaller files?

From Dev

How do I quickly (as quick as possible) list ten files from a very large directory, any files?

From Java

How to split a large text file into smaller files with equal number of lines?

From Dev

How do I split a large MySql backup file into multiple files?

From Dev

How can I keep multiple copies of a very large dataset in memory?

From Dev

Very large log files, what should I do?

From Dev

Very large log files, what should I do?

From Dev

How to append several large data.table objects into a single data.table and export to csv quickly without running out of memory?

From Dev

How can I compress a large file into smaller parts?

From Dev

How can I parallelize my macOS app tasks as much as possible without running out of memory?

From Dev

How do I print a large page on multiple smaller pages?

From Dev

How do I simulate a smaller monitor within a large monitor?

From Dev

PHP - How to do a string replace in a very large number of files?

From Dev

Count word occurences in very large file (memory exhausted on running) grep -o foo | wc -l

From Dev

What do I do about a machine that is running out of memory and crashing?

Related Related

  1. 1

    Read/download large file in PHP without running out of memory

  2. 2

    How to iterate a large table in Django without running out of memory?

  3. 3

    Calculate a large amount without running out of memory

  4. 4

    How do I process very large file (13GB) in python without crashing?

  5. 5

    How can I read tsv files and store them as hdf5 without running out of memory?

  6. 6

    How do I make a puzzle app in droid without running out of memory?

  7. 7

    How do I split a large sql databse backup file into smaller parts without messing up with the backed up queries?

  8. 8

    How to output a massive file with PHP without running out of memory

  9. 9

    How do I append a line to the beginning of a very large file in Linux?

  10. 10

    How do I search through a very large csv file?

  11. 11

    Cordova calculate sha1 hash of large file without running out of memory

  12. 12

    How do I suppress "low memory" warnings in Vista Home Premium when running without paging file?

  13. 13

    Bash script using gzip and bcftools running out of memory with large files

  14. 14

    Break large file into smaller files

  15. 15

    Can I split a large HAProxy config file into multiple smaller files?

  16. 16

    How do I quickly (as quick as possible) list ten files from a very large directory, any files?

  17. 17

    How to split a large text file into smaller files with equal number of lines?

  18. 18

    How do I split a large MySql backup file into multiple files?

  19. 19

    How can I keep multiple copies of a very large dataset in memory?

  20. 20

    Very large log files, what should I do?

  21. 21

    Very large log files, what should I do?

  22. 22

    How to append several large data.table objects into a single data.table and export to csv quickly without running out of memory?

  23. 23

    How can I compress a large file into smaller parts?

  24. 24

    How can I parallelize my macOS app tasks as much as possible without running out of memory?

  25. 25

    How do I print a large page on multiple smaller pages?

  26. 26

    How do I simulate a smaller monitor within a large monitor?

  27. 27

    PHP - How to do a string replace in a very large number of files?

  28. 28

    Count word occurences in very large file (memory exhausted on running) grep -o foo | wc -l

  29. 29

    What do I do about a machine that is running out of memory and crashing?

HotTag

Archive