From charlesreid1

No edit summary
Line 66: Line 66:


[http://docs.geoserver.org/stable/en/user/gettingstarted/shapefile-quickstart/index.html]
[http://docs.geoserver.org/stable/en/user/gettingstarted/shapefile-quickstart/index.html]
=Using Data from the Server=
In order to test out the server's capabilities, I wanted to visualize the New York City streets dataset that I just imported in a site with an embedded map. For this purpose, I can use Leaflet, the Javascript maps app. I'll feed Leaflet a GeoJSON URL for the New York City street data, which Geoserver will serve up.
This will have three parts:
* HTML (and CSS)
* Javascript
* URL for GeoJSON data
==Before We Begin==
The first thing we have to do, in order to access GeoJSON data via a URL, is fix the security settings of Geoserver. Right now, it is only set to serve up data to requests from "localhost." We will be accessing it from its IP address (and potentially other IP addresses, if it is a public server).
The error I was seeing was:
<pre>
XMLHttpRequest cannot load http://AAA.BBB.CCC.DDD:8080/geoserver/nyc_roads/ows?service=WFS&version=1.0.…&typeName=nyc_roads:nyc_roads&maxFeatures=50&outputFormat=application/json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://AAA.BBB.CCC.DDD' is therefore not allowed access.
</pre>
Searching yielded a stack overflow question: http://gis.stackexchange.com/questions/83272/geoserver-access-control-allow-origin
That mentioned ProxyPass for making requests for data from outside of localhost: http://www.gistutor.com/geoserver/21-intermediate-geoserver-tutorials/38-configuring-geoserver-proxy-for-public-and-remote-data-access.html
This involved editing the apache configuration file, at <code>/etc/apache2/sites-available/000-default.conf</code> on default Apache installations on Ubuntu systems, and added the following just before the <code>VirtualHost *:80</code> tag:
<pre>
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /geoserver http://localhost:8080/geoserver
ProxyPassReverse /geoserver http://localhost:8080/geoserver
</pre>
In plain English: when an outside server accesses the <code>/geoserver</code> directory, it is passed through a local proxy.
What a local proxy does is take requests from non-local servers to access the Geoserver, and makes them look like local requests.
Note that you'll have to do this, even if you're accessing Geoserver from the same IP address and the same machine, as long as you don't access Geoserver using an address like localhost:8080.
==Creating the HTML Site==

Revision as of 02:35, 2 February 2015

This guide (part 2) picks up where the Geodroplet page (part 1) left off:

http://docs.geoserver.org/stable/en/user/gettingstarted/web-admin-quickstart/index.html

Logging In

Username/Password

Default username/pw are admin/geoserver. First thing I did was change those.

Server Status

Server status page shows some useful info:

GeoserverServerStatus.png

Data

On the left hand side menu, there is a cluster of items labeled "Data".

Here is what "Stores" looks like:

GeoserverStores.png

There's also "Layers," "Workspaces," etc. Not clear what all of this is for, I'm just browsing through it... Geoserver documentation isn't saying much about what these things are. (This is the web interface quick start, after all...)

Tutorial

Here is a tutorial: http://docs.geoserver.org/stable/en/user/gettingstarted/shapefile-quickstart/index.html

Importing Shape Data

Download the NYC roads shape file package linked to in the tutorial.

This goes in the Geoserver data directory. Remember from the Geodroplet page that this is a directory in our Tomcat webapp directory, so the whole thing is at /var/lib/tomcat7/webapps/geoserver/data/data (NOTE THE DOUBLE DATA!).

Move the map data to the Geoserver data directory:

sudo mv nyc_roads /var/lib/tomcat7/webapps/geoserver/data/data/.

You'll also have to change the owner to the Tomcat user:

sudo chown -R tomcat7:tomcat7 /var/lib/tomcat7/webapps/geoserver/data/data/nyc_roads/

Now we keep following the instructions.

Creating Workspace

Still logged into the Geoserver web portal as the admin, we go to Data and Workspaces, on the left hand side menu.

We pick add a new workspace, name it and populate it following the tutorial instructions [1].

Creating Store

Followed the tutorial instructions to create a store for NYC roads data...

Creating Layer

Created a layer for looking at that map... this is a lot of steps, making for a cumbersome workflow...

And finally, the document ends, at an anticlimactic moment. The map isn't that interesting, there are no other satellite or other map layers on it, and I'm not sure what to do with this.

[2]


Using Data from the Server

In order to test out the server's capabilities, I wanted to visualize the New York City streets dataset that I just imported in a site with an embedded map. For this purpose, I can use Leaflet, the Javascript maps app. I'll feed Leaflet a GeoJSON URL for the New York City street data, which Geoserver will serve up.

This will have three parts:

  • HTML (and CSS)
  • Javascript
  • URL for GeoJSON data

Before We Begin

The first thing we have to do, in order to access GeoJSON data via a URL, is fix the security settings of Geoserver. Right now, it is only set to serve up data to requests from "localhost." We will be accessing it from its IP address (and potentially other IP addresses, if it is a public server).

The error I was seeing was:

 XMLHttpRequest cannot load http://AAA.BBB.CCC.DDD:8080/geoserver/nyc_roads/ows?service=WFS&version=1.0.…&typeName=nyc_roads:nyc_roads&maxFeatures=50&outputFormat=application/json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://AAA.BBB.CCC.DDD' is therefore not allowed access.

Searching yielded a stack overflow question: http://gis.stackexchange.com/questions/83272/geoserver-access-control-allow-origin

That mentioned ProxyPass for making requests for data from outside of localhost: http://www.gistutor.com/geoserver/21-intermediate-geoserver-tutorials/38-configuring-geoserver-proxy-for-public-and-remote-data-access.html

This involved editing the apache configuration file, at /etc/apache2/sites-available/000-default.conf on default Apache installations on Ubuntu systems, and added the following just before the VirtualHost *:80 tag:

ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /geoserver http://localhost:8080/geoserver
ProxyPassReverse /geoserver http://localhost:8080/geoserver

In plain English: when an outside server accesses the /geoserver directory, it is passed through a local proxy.

What a local proxy does is take requests from non-local servers to access the Geoserver, and makes them look like local requests.

Note that you'll have to do this, even if you're accessing Geoserver from the same IP address and the same machine, as long as you don't access Geoserver using an address like localhost:8080.

Creating the HTML Site