I'm looking for a rather basic PostGIS viewer. It should be possible to pan, zoom and retrieve coordinate information on mouse click. No need to support coordinate transformations. It should introduce as little further dependencies as possible. Preferably written in C++.
PostGIS Viewer – Finding a Basic PostGIS Viewer for Custom Application Development
postgis
Related Solutions
The easiest answer is to include a column with a colour code in your table that you fill in when you generate the row. You can then use a PropertyValue in the CssParameter tag
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">
<ogc:PropertyName>colour</ogc:PropertyName>
</CssParameter>
<CssParameter name="stroke-width">2</CssParameter>
</Stroke>
</LineSymbolizer>
If you want something that doesn't involve changing the table then you may be able to do something with a transformation function.
Dont be complicated if you can be simple.
1) Client-side: pure jQuery and html. JSON + Ajax to communicate with server.
function loadCities() {
var mapbounds = map.getExtent();
mapbounds.transform(toProjection, fromProjection );
bbox = mapbounds.toArray();
var bleft = bbox[0];
var bbottom = bbox[1];
var bright = bbox[2];
var btop = bbox[3];
showLoader();
var origem = "getCities?bleft=" + bleft + "&bbottom=" + bbottom + "&bright=" + bright + "&btop=" + btop;
$.ajax({
url: origem,
dataType: "json"
}).always(function() { hideLoader(); }).done(function(data) {
data = eval( data );
var geojson_format = new OpenLayers.Format.GeoJSON({
'internalProjection': map.baseLayer.projection,
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
citiesLayer.removeAllFeatures();
citiesLayer.addFeatures(geojson_format.read(data));
});
}
2) Server side: Struts Actions configured to JSON responses:
@Action(value="getCities", results= {
@Result(name="ok", type="httpheader", params={"status", "200"}) }
)
@ParentPackage("default")
public class GetCitiesAction {
public String execute(){
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(StrutsStatics.HTTP_REQUEST);
Double bleft = Double.parseDouble( request.getParameter("bleft") );
Double bbottom = Double.parseDouble( request.getParameter("bbottom") );
Double bright = Double.parseDouble( request.getParameter("bright") );
Double btop = Double.parseDouble( request.getParameter("btop") );
int idUsuario = Integer.valueOf( request.getParameter("idUsuario") );
String resposta = "";
try {
CityController cc = new CityController( idUsuario );
IStaticElementList lista = cc.getCitiesInBBOX( bleft, bbottom, bright, btop );
resposta = lista.asJson();
} catch ( Exception e ) {
e.printStackTrace();
}
try {
HttpServletResponse response = (HttpServletResponse)ActionContext.getContext().get(StrutsStatics.HTTP_RESPONSE);
response.setCharacterEncoding("UTF-8");
response.getWriter().write(resposta);
} catch (IOException ex) {
ex.printStackTrace();
}
return "ok";
}
}
Hybernate to database access. Don't forget to keep the domains. See Domain Driven Design. Mail me if in doubt (see my profile).
Best Answer
Although this isn't really the direct answer to your question, qgis acts as a relatively simple GIS viewer which can access PostGIS. In addition to the main application -- which is a relatively complex piece of software -- the core of the qgis library can be 'pulled out' and used from an application written in C/C++ or (I believe, with some work) Python.
Tim Sutton's post on the topic of building minimal qgis widgets is probably a good starting place for this. In order to build a simple widget for viewing a layer, the C code is only 63 lines, including headers + other boilerplate.