From a clean Ubuntu 12.04 Precise install I was able to get it to work with this:
echo 'deb http://ppa.launchpad.net/ubuntugis/ppa/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
echo 'deb-src http://ppa.launchpad.net/ubuntugis/ppa/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 314DF160
sudo apt-get update
sudo apt-get install -y postgresql-server-dev-9.1 postgis python-mapscript python-gdal
For more up-to-date gis packages use the unstable repository
echo 'deb http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
echo 'deb-src http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
This also works for Ubuntu 14.04 Trusty, just replace precise
with trusty
when adding the ubuntugis repos. Then you can also install postgres 9.3 instead of 9.1. So on Trusty use:
sudo apt-get install -y postgresql-server-dev-9.3 postgis python-mapscript python-gdal
The two references for installing this I used were
http://trac.osgeo.org/ubuntugis/wiki/UbuntuGISRepository
https://launchpad.net/~ubuntugis/+archive/ubuntu/ppa/
Also, if you want to use the postgis raster driver through mapscript, it is worth trying to install the latest GDAL version, as it has essential improvements on the raster driver (its much faster and more stable). So in that case I would recommend the unstable repo, in my work so far I did not run into problems due to the "unstable" name.
If you want to display your shapefiles on the map canvas, it can be done by creating .kml files.
First in models.py create functions to convert data to .kml:
def shpPoint(request):
points = ShapefilePoint.objects.kml()
return render_to_kml("placemarks.kml", {'places': points})
placemarks.kml is a simple template for that purpose, it can be found in geodjango documentation I guess:
{% extends "base.kml" %}
{% block placemarks %}{% for place in places %}
<Placemark>
<name>{% if place.name %}{{ place.name }}{% else %}{{ place }}{% endif %}</name>
<description>{% if place.description %}{{ place.description }}{% else %}{{ place }}{% endif %}</description>
{{ place.kml|safe }}
</Placemark>{% endfor %}{% endblock %}
and function to rendering:
def index(request):
return render_to_response("map.html")
Now map your kml link in urls.py:
...
url(r'^point/', shpPoint),
...
And finally you can add your layer in JS code (this code contains example styling for point layer):
var PointLayer = new ol.layer.Vector({
title: 'Point',
source: new ol.source.KML({
projection:new ol.proj.get("EPSG:3857"),
url:'http://localhost:8000/point/',
extractStyles: false
}),
style: (function() {
var textStroke = new ol.style.Stroke({
color: 'yellow',
width: 3
});
var textFill = new ol.style.Fill({
color: 'black'
});
return function(feature, resolution) {
return [new ol.style.Style({
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({color: 'yellow'}),
stroke: new ol.style.Stroke({color: 'red'})
}),
text: new ol.style.Text({
font: '11px arial,sans-serif',
text: feature.get('name'),
fill: textFill,
stroke: textStroke,
offsetX: 25,
offsetY: -10
})
})];
};
})()
});
map.addLayer(PointLayer);
Best Answer
You will need to build two parts to record user locations:
PointField
field.Good luck!