Converting a open street map database to a raster attribute table - openstreetmap

I'm new to OSM and analyzing maps in general. My task is to convert a certain area from OSM (which is given in an XML format and can be converted to different types of databases) to a tensor where two dimensions give the area (to a certain resolution), and the third dimension is the "layers" - eventually getting layered matrices of bits for each possible attribute.
For example, if the area is 2*2 (it could be more or less depending on chosen resolution) and the possible attribute are buildings, trees, and roads, then the tensor would be of 2*2*3: 3 layers of 2*2 matrices for the attributes. Cell (i,j,k) in the tensor is 1 if and only if the attribute k exists in the location i,j on the map.
I tried looking online and using gdal, qgis and I am pretty lost.
Is such a procedure possible?

I do not have any experience with rasters, so I can only answer the first part of your quenstion.
Get an OSM-map with the following code:
library( OpenStreetMap )
LAT1=52;LAT2=54;LON1=4;LON2=6
#get an openstreetmap
map.osm <- OpenStreetMap::openmap( c( LAT1 - 1, LON1 - 1 ),
c( LAT2 + 1, LON2 + 1 ),
zoom = NULL,
type = "https://basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png",
mergeTiles = TRUE)
#plot with latest version of ggplot2
ggplot2::autoplot( map.osm )
You can (probably) build a raster using raster::raster( map.osm ), since raster contains a method for OpenStreetmapObjects

Related

Mixing a line with pies or sectors

A table consists of 4 fields:
X: time values in ascending order
Y: numeric value - double
A: numeric value - int
B: numeric value - int
I need to create a line chart using the X,Y values. And at each of the x,y points also show a pie/circle representing the A,B values as follows:
The centre of the pie is the x,y point.
The diameter of the pie is calculated from the values A and B.
The pie will have 2 different coloured slices, the size of each slice is proportion to the value of A and B.
After searching the documentations of lcjs, can this be done using Lightning Charts JS? if not, how about lc.NET?
Any hints is much appriciated.
Thank you
In LightningChart JS, I don't believe there is such functionality available.
Something like this should be possible (bar instead of pie)

Incorrect coordinates in mbtiles generated with Tippecanoe

I generated an mbtiles file using Tippecanoe with just -zg and --drop-densest-as-needed as extra parameters. I uploaded the file to Mapbox Studio and everything works well, both in Studio and when loading the tiles through a mobile app.
I then tried my luck at self-hosting the tiles, using a very basic HTTP server in Go. Tiles were transferred from SQLite to a PostgreSQL database (the reason for this is Go + PSQL is the existing stack for the app).
For some reason the features are shifted depending on the zoom level. At level 1, data that's supposed to be in the US is in the Antarctic, at zoom level 2 it's off the coast of Chile, etc. The only one properly working is level 0 as there's only one tile.
I checked what tiles Mapbox was requesting when in San Francisco for zoom level 11: column 327, row 791. No tile exists for this row/col combination in the .mbtiles file although there's data there.
Is there additional things to be done to the mbtiles besides looking them up in the database using the z/x/y? Or maybe stuff to configure on the app side?
Server code:
row := db.QueryRow(`
SELECT tile_data FROM tiles
WHERE
zoom_level = $1
AND tile_column = $2
AND tile_row = $3
`,
z, x, y,
)
On Android:
map.addSource(
VectorSource(
"tiles",
TileSet("2.2.0", "http://my.local.server:4000/tiles/{z}/{x}/{y}.mvt?key=2448A697EACDDC41432AAD9A1833E")
)
)
I tried setting the VectorSource's center and bounds found in the mbtiles metadata but it didn't change anything.
So I looked into existing server implementations and it turns out the offset is because the mbtiles are stored in a TMS format in which the Y coordinate is flipped. So we just need to convert the Y from the XYZ format to get the proper tile:
From Mapbox's own Node implementation:
// Flip Y coordinate because MBTiles files are TMS.
y = (1 << z) - 1 - y;
1 << z is the number of rows for a given zoom level, or two to the power of z.
More info about XYZ vs TMS can also be found here.

How to adjust rows and columns, retaining cell sizes in arcmap?

The Situation: I have a vector data map with all the countries in the World, including a unique landcode for every country. I need to convert it into a raster map, so I can eventually analyse (with Matlab) drought indicators for that country.
The Problem: The precipitation data I use has 720 columns and 360 rows. I want the raster map of world countries to be in the exact same amount of columns and rows. BUT the raster map also needs to have a cellsize of 0.5! Right now, when I use the vector to raster conversion tool, if I use cellsize = 0.5, the columns and rows become 720x287.
Question: How can I create a raster map of 720 columns and 360 rows, while setting cellsize at 0.5?
Thank you in advance!
Additional info:
Using ArcMap 10.4.1 and Matlab R2015b
Raster is .TIFF
Vector is .shp
As a fellow GIS user I would recommend posting your question under the GIS stack exchange, https://gis.stackexchange.com/
Beyond that there is some clarification needed. Are you saying that you are trying to create a multi band raster with 1 band for each column?
I solved the problem. In ArcMap, I imported the precipitation data (NetCDF). It was however flipped, but I could get it in the right orientation using the tools 'Flip' and 'Rotate'. Now this map had the right orientation and the right amount of columns and rows. Furthermore I just altered some of the default settings in environments: 1) I set the processing extent to the precipitation data. 2) I set the snap raster also to the precipitation data. 3) I set the cellsize of every output raster to 0.5. Finally, I converted the vector file of world countries to a ASCII file using the raster to ascii conversion tool. The ASCII file now has the same amount of rows and columns as the precipitation data!

How to calculate width and lengths of street in PostgreSQL?

I am already aware that this question, more specifically, should have been directed to GIS StackExchange. I already asked the question here but sadly, got no answers or any suggestions. I used ST_ClosestPoint() to project a point to the nearest line (point on line interpolation) using this approach.
Select ST_ClosestPoint(line, pt) As closest_pt_line
From
(Select ad.geom As pt,
st.geom As line,
ST_Distance(ad.geom, st.geom) As d
From ad, st
Where ST_DWithin(st.geom, ad.geom, 10.0)
Order By d
) As foo;
Based on this projected point, I need to calculate the length of street in both directions and width of street by making using of building polygons layer. The scenario can be visualized like this:
Visualization of the scenario
I am aware of ST_Length function but it returns the length of whole linestring rather than length 1 and length 2. Any advice to calculate lengths of street and width would be highly appreciated?

Put points on the map, longitude/latitude not where they should be although SRID the same

Thank you for looking at this - I'm sure it's a simple question but this is all very new to me and after a lot of internet searching my points are still in the sea!
I have a set of UK postcode data that I have converted into latitude and longitude. I also have a UK counties shape file.
The code that I have used to convert the latitude/longitude to a geometry point column is as follows:
ALTER TABLE colic ADD COLUMN longlat geometry(POINT,27700);
update colic set longlat = st_setsrid(st_point( longitude, latitude), 27700);
And this produces a column that has values as follows (I've only included a couple!):
"0101000020346C000048BF7D1D3867E83FC05B2041F1334A40"
"0101000020346C0000F085C954C1A8F7BFA1F831E6AE954A40"
"0101000020346C000020D26F5F07CEF4BFE3361AC05B504A40"
"0101000020346C00007D3F355EBA49F73FB6847CD0B3614A40"
The .prj from my shape file is:
PROJCS["British_National_Grid", GEOGCS["GCS_OSGB_1936",
DATUM["D_OSGB_1936", SPHEROID["Airy_1830",6377563.396,299.3249646]],
PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],
PROJECTION["Transverse_Mercator"],
PARAMETER["False_Easting",400000.0],
PARAMETER["False_Northing",-100000.0],
PARAMETER["Central_Meridian",-2.0],
PARAMETER["Scale_Factor",0.9996012717],
PARAMETER["Latitude_Of_Origin",49.0], UNIT["Meter",1.0]]
And I set its SRID to 27700 when I upload it using the PostGIS shapefile uploader.
In PG Admin, when I ask:
select st_srid(geom) from counties limit 1;
select st_srid(longlat) from colic limit 1;
I get 27700 for both.
But...when I try any spatial query I get no response, and when I load the layers into quantum, the point data are off the tip of Cornwall in the north Atlantic, and only represented as one dot on the scale of the counties map.If I zoom in on them, they are 'there', but just not in east anglia where they should be!
This is my first attempt at both SQL and mapping - I'm sure there is something really simple that I have missed.
You are mixing up spatial references (SRS). The SRS in the .prj file (aka SRID=27700) is projected eastings and northings, which have units of metres. This is not latitude and longitude! Furthermore, it is a deception to call a column longlat when it isn't for longitude/latitude coordinates.
If you try to insert latitude/longitude in a column with SRID=27700, the points will not behave as expected, e.g., they will be in the far bottom left corner of a map.
If you have lat/long data from WGS84 (SRID=4326), you can transform this to eastings and northings:
UPDATE colic SET
geom = ST_Transform(ST_SetSRID(ST_Point(longitude, latitude), 4326), 27700);