Tuesday, May 19, 2009

Black areas in Silverlight Map Control using GeoWebCache


Strange behavior in Silverlight map control (SMC).


This blog from Randy George shows how to use GeoServer GeoWebcached layers in the Silverlight map control:




Very nice, works well. I used this syntax for my Tile Source




which pulls tiles from the GeoWebCache.


Problem is, some of our layers have a smaller coverage area than others. GeoWebCache is smart enough to not try to generate tiles if the layer doesn't cover the area. Problem is, that the SMC shows a tile that doesn't return data as BLACK. Very ugly - see picture.
So, how to fix? Likely this is a bug in the SMC, so it needs to be fixed there. But in the meantime, you can change the extents of your GeoServer layer to be larger. Then, reload the GeoWebCache by going to the http://yourserver:8080/geoserver/gwc/demo and clicking on "Reload Configuration" - or possibly restarting GeoServer, I didn't try that.
Then GWC will send back transparent PNGs instead of nothing at all, and the SMC is happy.





Monday, May 18, 2009

Adding Personalization to ASP.NET with PostGIS (PostgreSql)

Next step - adding personalization to the web site using Postgresql.

Very easy, as well as documented.

Just go to:

http://dev.nauck-it.de/aspsqlprovider/

and follow the directions.

One thing not mentioned is the PostgreSQL encoding of the database when you create it. I used the default Win1252, which seemed to work fine.

I created the database, ran the SQL script to create the tables, and added/modified the web.config file.

Created a asp.net web form with a login control, ran it, but it didn't work. Got:

at NauckIT.PostgreSQLProvider.PgMembershipProvider.ValidateUser(String username, String password) in C:\Users\Daniel Nauck\Documents\Visual Studio 2008\Projects\PostgreSQLProvider\PgMembershipProvider.cs:line 1229 at System.Web.UI.WebControls.Login.AuthenticateUsingMembershipProvider(AuthenticateEventArgs e)

Well, that was a bit disconcerting. So, looked at the Immediate window in VS2008, for more info, and saw:

Npgsql.NpgsqlException:
syntax error at or near "("
Severity: ERROR
Code: 42601
at Npgsql.NpgsqlState.d__a.MoveNext()
at Npgsql.NpgsqlState.IterateThroughAllResponses(IEnumerable`1 ienum)
at Npgsql.NpgsqlState.ProcessBackendResponses(NpgsqlConnector context)
at Npgsql.NpgsqlReadyState.Flush(NpgsqlConnector context)
at Npgsql.NpgsqlConnector.Flush()
at Npgsql.NpgsqlCommand.Prepare()
at NauckIT.PostgreSQLProvider.PgMembershipProvider.ValidateUser(String username, String password) in C:\Users\Daniel Nauck\Documents\Visual Studio 2008\Projects\PostgreSQLProvider\PgMembershipProvider.cs:line 1210
A first chance exception of type 'System.Configuration.Provider.ProviderException' occurred in NauckIT.PostgreSQLProvider.DLL

Not too helpful...

Then tried various things, made sure the uid and password was ok, changed the name of the application to the name of my project, etc. These had no effect.

Then, did a get of the latest Nauck from SVN and added to my solution. Then it started working. Perhaps the release 1.240 is a little bogus? Anyway, now it works. Awesome.

Tuesday, May 12, 2009

Converting a Lat Long to a USGS Quarter Quad Number in VB

USGS uses an odd system of numbering the 24k quads, and quarter quads.
it uses lat, lon(lower RIGHT corner), then letters A - H from right to left, and 1 -8 from bottom to top. Quarter quads are then numbered 1 is upper right, 2 is upper left, 3 is lower left, 4 is lower right of the whole quad. eg 33106-E32 where the 2 at the end is the qq number.

An irritating little problem, but here is a solution in VB.net


Given a lat-lon, what is the USGS quad number (or USGS quarter quad in this case)

Private Function LatLonToQQName(ByVal Latitude As Double, ByVal Longitude As Double) As String

'What is the Longitude whole number part (degree) of the right corner
Dim LonDegree As Integer = Math.Ceiling(Longitude)

'Get the fractional part of lon
Dim FLon = LonDegree - Longitude

'Calculate the Number, from 1 to 8, starting from right corner
Dim Number As String = Math.Ceiling(FLon / 0.125).ToString

'Next, the number, from 1 to 8, starting from bottom
Dim LatDegree As Integer = Math.Floor(Latitude)

'Get the fractional part of lon
Dim FLat = Latitude - LatDegree

Dim Letter = Chr(Asc("A") + Math.Floor(FLat / 0.125)).ToString

'Finally, the QQ number (from 1 to 4) 1 is upper right, 2 is upper left, 3 is lower left, 4 is lower right
Dim QQNumberLon As Integer = Math.Floor((FLon / 0.125 - Math.Floor(FLon / 0.125)) * 2)
Dim QQNumberLat As Integer = Math.Floor((FLat / 0.125 - Math.Floor(FLat / 0.125)) * 2)

Dim QQNumber As String = ""
If QQNumberLat = 0 And QQNumberLon = 0 Then
QQNumber = "4"
ElseIf QQNumberLat = 0 And QQNumberLon = 1 Then
QQNumber = "3"
ElseIf QQNumberLat = 1 And QQNumberLon = 1 Then
QQNumber = "2"
ElseIf QQNumberLat = 1 And QQNumberLon = 0 Then
QQNumber = "1"
End If

Return LatDegree.ToString & (Math.Abs(LonDegree)).ToString("D3") & "-" & Letter & Number & QQNumber
End Function

Saturday, November 1, 2008

GeoServer 1.70 Setup with MrSID and GeoWebCache

Here are the procedures I used to successfully setup GeoServer 1.70 on a Windows 2003 server:

1) Download the latest Java SE JDK (I used http://java.sun.com/javase/downloads/index.jsp )
and install it to where you like.

Set an environment variable (I did a System EV) for JAVA_HOME to point to the directory where the JDK is installed.

2) Download GeoServer 1.70 from geoserver.org. Install it, choosing your install directory and data directory. Note that if you chose a different data directory than the default like I did, you will have to move all the contents of the data_dir from the geoserver install directory to your own data directory.

3) Follow the instructions carefully from:
http://geoserver.org/display/GEOSDOC/ImageIO-ext+GDAL+extensions
to install the Image-IO extensions. Note that you have three downloads, one is the JAR files from the main GeoServer 1.7 download page, and two from this page.

4) Download the GeoWebCache extension from the main GeoServer download page, and copy the JAR files from the zip to the program_files/geoserver_directory/webapps/geoserver/WEB_INF/lib . This is also stated in the readme inside the zip

5) Fire up Geoserver from the start menu entry for Geoserver. Say yes to any warnings about firewall.

6) Start up the Geoserver administrator from the same place. Go to Demos and try the Map Preview for some layers to see if everything is working.
Go to Config|WCS|CoveragePlugins and verify that MrSID is there.

7) Copy your MRSID files to your geoserver data directory/coverages/MrSIDSample

8) Follow the instructions on this page, to create the mosaic.

http://geoserver.org/display/GEOSDOC/Using+the+ImageMosaic+plugin

Use the GDALTIndex instructions. This will create the SHP file for the mosaic. I usually copy GDALTINDEX.exe and all the rest of the GDAL utilities (GDAL version 1.4) into the JAVA_HOME/bin, and add this path to the path environment variable.

Open a command window. Go to the directory where the MrSids are.

To quickly create the SHP file,

for %q in (*.sid) do gdaltindex mrsidsample %q

then you will have the .SHP done.
Next create a .PRJ file for the projection. This is a little tricky, but it is a WKT prj the same as from a SHP file. Name it the same mrsidsample.prj

Finally, create a mrsdidsample.properties file, in our case this is:

Name=MrSidSample
Levels=1.0,1.0
LevelsNum=1
Envelope2D=360646.500000,3728054.500000 372944.500000,3735762.500000
NumFiles=2

Create a Mosaic coverage and test it in demos. It should appear.



Finally, to test the GeoWebCache, first create a new WMS layer-group MrSID4326, generate the bounding rectangle, test it in demo.

then create an open layers html page that accesses the cache