= Housing selector
:description: Documentation for the project
:sectanchors:
:url-repo: https://git.tammi.cc/housing.git

SVG and WGS94 https://www.w3.org/TR/SVG11/coords.html

The project consists of three parts:

1. Application (native web browser)
2. CouchDB and S3
3. Scraper (Golang)

The developments tools are listed in flake.nix and development environment can be start with command:

[source,bash]
----
nix develop
----

== Application

There is a development server `server.js` that serves the app and static assets.
The application resides in app directory.

[%header,format=tsv]
|===
include::app/requirements.tsv[]
|===

Run (the development server) with:

[source,bash]
----
node server.js
----

Static assets are deployed to web server.

== Scraper runner

Golang is used to fetch the data to CouchDB.
The runner resides in scrape directory.

[%header,format=tsv]
|===
include::scrape/requirements.tsv[]
|===

The running will require some cookies to be gotten from a web browser. Run with:

[source,bash]
----
export OTA_TOKEN=...
export OTA_CUID=...
export OTA_LOADED=...
export PHPSESSID=...

go run main.go
----

== Next steps

- Implement additional map features, "metro", "pikaraitiotie", "koulut", "kaupat".
- Add possibility to color districts based on data such as crime rate, etc.
- Make the weight calculation work.
- Fix the map zoom and initial viewport
- Add links to house details on the service. Add additional images
- Parse more data from data source. Now only overview is parsed.
- Images on modal open on click to a new window
- Visual programming? Value function description with javascript?
- Notifications to user on new houses
- Sharing via URL
- Real support for MultiLineString in geometry

== Analysis Data processing

List of open WFS data sources are in:
https://kartta.hel.fi/avoindata/dokumentit/Aineistolista_wfs_avoindata.html

WFS Capabilities can be found from:
https://kartta.hel.fi/ws/geoserver/avoindata/wfs?version=2.0.0&request=GetCapabilities

The data can then be downloaded with CURL.

=== Roads
[source,bash]
----
# First download the full dataset
curl -X GET \
  "https://kartta.hel.fi/ws/geoserver/avoindata/wfs?\
service=WFS&\
version=2.0.0&\
request=GetFeature&\
typeNames=avoindata:Liikennevaylat&\
outputFormat=application/json" \
  -o liikennevaylat_full.geojson

# Then filter with jq
jq '{
  type: .type,
  features: [.features[] | select(.properties.alatyyppi == "Moottoriväylä")],
  crs: .crs
}' liikennevaylat_full.geojson > moottorivaylat.geojson
----

[source,bash]
----
jq '[.features[].properties.paatyyppi | select(. != null)] | unique' liikennevaylat_full.geojson
----

=== Train stations
[source,bash]
----
curl -X GET \
  "https://kartta.hel.fi/ws/geoserver/avoindata/wfs?\
service=WFS&\
version=2.0.0&\
request=GetFeature&\
typeNames=avoindata:Seutukartta_liikenne_juna_asema&\
outputFormat=application/json&\
srsName=EPSG:4326" \
  -o juna_asemat.geojson
----


=== Railway lines

[source,bash]
----
curl -X GET \
  "https://kartta.hel.fi/ws/geoserver/avoindata/wfs?\
service=WFS&\
version=2.0.0&\
request=GetFeature&\
typeNames=avoindata:Seutukartta_liikenne_juna_rata&\
outputFormat=application/json&\
srsName=EPSG:4326" \
  -o juna_radat.geojson
----
