Do I need specific configuration for Spatialite with GeoDjango? - django

According to https://docs.djangoproject.com/en/1.3/ref/contrib/gis/db-api/, Spatialite supports GeoQuerySet.distance(). However, having imported an area list (MultiPolygon as mpoly attribute), I'm trying to do the following:
Area.objects.all().distance(center)
And instead of something usable, I only get an error message: "ValueError: SQLite does not support linear distance calculations on geodetic coordinate systems."
What's wrong here, do I need some special configuration on Spatialite or is the documentation plain wrong?

You don't need to do anything regarding spatialite, but rather change the coordinate system (srid) you're using. Spatialite does distance calculations only on geographic coordinate systems, not geodetic. Check the SRID do you have in your model definition. Alternatively you can also switch to the postgis backend.

Related

How to add attributes in combination of object detection using YOLO?

I'm new to computer vision and I'm wondering how to deal with the following problem.
I'm using YOLO for real time objet detection task. However I'm dealing with a dataset that gives me also few attributes such has weather, temperature etc...
(I'm obviously able to acces to those informations in real time, to use them in real life).
My data has some big differences depending of the weather, temperature etc... that's why it's useful to have access to those informations.
So is there any way to learn on both image dataset associated to a context ? I'm looking for something that is YOLO compatible.
If a such thing isn't compatible/doesn't exists, I guess I'll just do different versions of the trained YOLO on specifics datasets associated to different context. Each specific version will be actived only for specific weather and temperature.
Thank you in advance for any kind of help/informations.
You will need to build you custom model that combines visual features with tabular data. This could look something like:
vis_feats = nn.Linear(512, 1) # visual features
tab_feats = nn.Linear(4, 1) # tab features
x = torch.cat((x, tab), dim=1) # x goes into your prediction layer

How to output the final tableau of simplex method in docplex?

Is there a way to output the final tableau in python with docplex library? If not, is there a work around?
I want to use dual simplex method to solve linear programming problem with newly added constraints. So, I would need to access the final tableau to decide which variable to exit the basis, without having to re-solve the problem from scratch.
This sort of low level interaction cannot be done at the docplex level. In order to do this you can use Model.get_cplex() to get a reference to the underlying engine object. With this you can then get additional information. You can find the reference documentation for this class here. You probably want to look at the solution, solution.basis, solution.advanced properties. This should give you all the information you need.
Note that the engine works with an index oriented model in which every variable or constraint is just a number. You can convert docplex variable objects by using Model.get_var_by_index().
I also wonder whether you may want drop docplex and instead directly use the CPLEX Python API. You can find documentation of this here.

Converting coordinates from SVY21 to WGS84

I am trying to transform the SVY21 coordinates I have to the WGS84 coordinate system.
I tried using the GDAL software and pasted the following into command after installing:
ogr2ogr -f GeoJSON –t_srs WGS84 <jsonFileName>.json <shapefile>.shp
It results in the failure:
Unable to open datasource 'WGS84' with the following drivers
And the drivers are listed.
Also I tried to use the python utm package to convert the N48 utm coordinate to WGS48, but I did not manage to convert the SVY21 coordinates to the N48 utm reference point.
I found the proposed solution in this old post confusing in terms of terminology and I would prefer using some existing solution.
Is there a "easy" solution that makes use of my previous approaches or is quickly applicable to my problem? I would also be happy if someone could provide me with a more precise explanation of the approach featured in the older post.
Thanks in advance.
Edit: I tried writing a python script that implements the vicenty direct calculation from the "old post" mentioned before. It would also help, if someone could confirm that substracting the False Coordinates of Projection Origin (28001.642mE,38744.572mN) from the raw svy21 (e,n) and using the Projection Origin (Unmarked point) (103° 50' 00", 1° 22' 00") is correct.
I was compiling gdal by hand and I could use the following command to do what you wanted:
You have to copy the *.shp (and *.shx) files beside the ogr2ogr-command (Source: https://gis.stackexchange.com/questions/56652/how-to-move-and-open-shapefiles-with-ogr2ogr)
gdal does not immediately know "EPSG:3414" - the EPSG name for SCY21, so give it a hint, this is in the [INSTALL LOCATION]/data (i dont know where it is on an installed version, especially not on windows. Search for a file called "gcs.csv", and point GDAL_LOCATION to the containing folder.
define t_srs and s_srs eccordingly
Define the output format ("GEOJson")
Summa summarum:
GDAL_DATA="../data" ./ogr2ogr -f "GEOJson" "LaneMarking_wgs84.json" "LaneMarking.shp" -t_srs WGS84 -s_srs "EPSG:3414"
Have fun :)

How to use OpenStreetMap background on Matplotlib Basemap

This should be simple, but when I look for it I just find web packages. I need something better than as oriented on This Blog. Maybe using .oms file or shapefiles. Some way to give bbox and get the OpenStreetMap background on Basemap map.
I found some questions like this on Stack, but the answers directs to, or download the .png file on OpenStreetMap website, or to use some web package.
I would suggest not to try to make something work, which is not made (yet) to work together.
There is a simple way to achieve what you want with Mplleaflet.
https://github.com/jwass/mplleaflet
The library allows you to visualize geographic data on a beautiful interactive openstreetmap. Map projection of data in long lat format is automatically performed.
Installation in windows and ubuntu is easy:
pip install mplleaflet
You can start with the provided examples and go from there.
There are many libraries today that can do this for you - smopy, folium and tilemapbase are three examples from my recent use.
Each of these tools fetch map tiles from the one of several servers that host OSM or other (Stamen, Carto, etc) map tiles and then allows you to display and plot on them using matplotlib. Tilemapbase also caches the tiles locally so that they are not fetched again the next time.
But there does not seem to be a readily available tool yet, based on my recent experience, to use offline tilesets (such as a compressed .mbtiles file) as background for matplotlib plotting.
This link contains a survey of the above tools and more - https://github.com/ispmarin/maps
EDIT
I had mentioned in my previous answer that Tilemapbase did not work for some geographical locations in the world, and hence explicitly recommended not to use it. But it turns out I was wrong, and I apologize for that. It actually works great! The problem in my case was embarrassingly simple - I had reversed the order or lat and lon while fetching tiles, and hence it always fetched blank tiles for certain geographical locations, leading me to assume that it did not work for those locations.
I had raised the issue in github and it was immediately resolved by the developers. See it here - https://github.com/MatthewDaws/TileMapBase/issues/7
Note the responses:
Coordinates are to be provided in order (1) longitude, (2) latitude. If you copied them from Google Maps, they will be in lat/lon order and you have to flip them. So your map image is not empty, it's just a location in the ocean north of Norway.
And from the developer himself:
Yes, when I wrote the code, it seemed that there wasn't a universal standard for ordering. So I chose the one which is different to Google Maps. The method name from_lonlat should give a hint as to the correct ordering...
For those who are using Cartopy, this is relatively simple:
import matplotlib.pyplot as pl
import numpy as np
import cartopy.crs as ccrs
import cartopy.io.img_tiles as cimgt
request = cimgt.OSM()
# Bounds: (lon_min, lon_max, lat_min, lat_max):
extent = [1, 13, 45, 53]
ax = pl.axes(projection=request.crs)
ax.set_extent(extent)
ax.add_image(request, 5) # 5 = zoom level
# Just some random points/lines:
pl.scatter(4.92, 51.97, transform=ccrs.PlateCarree())
pl.plot([4.92, 9], [51.97, 47], transform=ccrs.PlateCarree())
This produces:
You can download the necessary tiles yourself from one of the tile servers. The OSM wiki explains the technical details behind slippy map tilenames and also includes examples for various programming and scripting languages.
Please also read about the tile usage policy and keep in mind that different tile serves may have different policies.
This is very easy with geopandas and contextily.
Have a look at https://geopandas.org/gallery/plotting_basemap_background.html.

What is the way to implement neural networks in c/c++?

I wanted to use neural networks for pattern matching in c++. The scenario is like this:
The main goal is to determine a product by name when captured by a camera.
A rectangular pack of a product (say for example the container of a toothpaste product) is cut into its edge so that the all of its side are shown in one plane. The camera takes a picture of the pack and compare its patterns to the database.
If the patterns are found from the search, then display the name of the product.
Else, store the patterns of the product to the database with its name (say the brand of the toothpaste).
What I mean by pattern is the distinct feature of the product pack among the other products.
I want to know the following using c/c++ (linux, windows, or mac os doesn't matter):
Is there a library that makes work somehow easier?
If a library is not available, what is the best algorithm you can suggest for pattern matching?
I think first, you will need to do some post processing on picture captured by a camera to normalize it (size, angle, ...) For that job, you can use OpenCV.
Then if you want to setup a NN, maybe you should give a try to FANN (Fast Artificial Neural Network) http://leenissen.dk/fann/wp/
The library is compatible with Linux/Windows and really easy to use!