Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conservation district data to application #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@

#Ignore precompile.
public/assets/**

# Ignore .DS_Store
.DS_Store

4 changes: 1 addition & 3 deletions AddDataREADME.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,5 @@ Open up app/controllers/addresses_controller.rb

NOW DESCRIBE HOW TO ADD THIS JUNK.

Let's check and see if this worked. Go ahead and find an address that you know is inside your new polygon.

###
Let's check and see if this worked. Go ahead and find an address that you know is inside your new polygon.

25 changes: 24 additions & 1 deletion app/assets/javascripts/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var historicDistrictLayer = L.mapbox.featureLayer()
.addTo(map);
var cosaDistrictLayer = L.mapbox.featureLayer(null, {fill: 'red'})
.addTo(map);
var consDistrictLayer = L.mapbox.featureLayer(null, {fill: 'green'})
.addTo(map);

var marker = L.marker(new L.LatLng(29.423889, -98.493056), {
icon: L.mapbox.marker.icon({'marker-color': 'CC0033'}),
Expand Down Expand Up @@ -84,15 +86,36 @@ function updateMarker(d) {
cosaDistrictLayer.setFilter(function() { return false; });
}

var consDisStr = "";
var consDisStrPretty = "";
var consDistLegend = "";
var consDistColor = 'green'; // This is the color for the key
if (data.in_cons_district) {
var geoJSONcons = $.parseJSON(data.cons_district_polygon.st_asgeojson);
geoJSONcons.properties= {};
geoJSONcons.properties.fill = consDistColor;
consDistrictLayer.setGeoJSON(geoJSONcons);
consDistrictLayer.setFilter(function() { return true; });
consDisStr = "<br>COSA District: " + data.cons_district_polygon.district +
"<br>City Council: " + data.cons_district_polygon.name;
consDisStrPretty = "<p class=\"kicker\">Conservation District</p><p>" + data.cons_district_polygon.name + "</p>";
consDistLegend = "<li><span style='background:" + consDistColor + ";'></span>Conservation District</li>";
hasLegend = true;
}
else {
consDistrictLayer.setFilter(function() { return false; });
}

// marker.setPopupContent("Address: " + data.address + cosaDisStr + histDisStr);
$( "div.results-container" ).replaceWith(
"<div class=\"results-container\"><div class=\"results-inner\"><h3>This is what we know about this address:</h3><p class=\"kicker\">Address</p><p>" +
data.address + "</p>" + cosaDisStrPretty + histDisStrPretty + "</div></div>" );
data.address + "</p>" + cosaDisStrPretty + histDisStrPretty + consDisStrPretty + "</div></div>" );
if (hasLegend)
{
$("#legend-content").replaceWith("<div id='legend-content' style='display: none;'><ul class=\"ordering\">" +
histDistLegend +
cosaDistLegend +
consDistLegend +
"</ul><div class='legend-source'>Source: <a href=\"http://www.sanantonio.gov/GIS\">San Antonio GIS Data</a></div></div>");

console.log(document.getElementById('legend-content').innerHTML);
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ def index
address = Geokit::Geocoders::MultiGeocoder.geocode params[:address]
@in_hist_district = HistoricDistrict.inDistrict? address.lat, address.lng
@in_cosa_district = CosaCouncilDistrict.inDistrict? address.lat, address.lng
@in_cons_district = ConservationDistrict.inDistrict? address.lat, address.lng
@lat = address.lat
@lng = address.lng
@addr = address.full_address
@hist_district_polygon = HistoricDistrict.getDistrict address.lat, address.lng
@cosa_district_polygon = CosaCouncilDistrict.getDistrict address.lat, address.lng
@cons_district_polygon = ConservationDistrict.getDistrict address.lat, address.lng
end

if params[:lat] != nil and params[:long] != nil and !params[:lat].empty? and !params[:long].empty?
address = Geokit::Geocoders::MultiGeocoder.reverse_geocode "#{params[:lat]}, #{params[:long]}"
@in_hist_district = HistoricDistrict.inDistrict? params[:lat], params[:long]
@in_cosa_district = CosaCouncilDistrict.inDistrict? params[:lat], params[:long]
@in_cons_district = ConservationDistrict.inDistrict? params[:lat], params[:long]
@lat = params[:lat]
@lng = params[:long]
@addr = address.full_address
@hist_district_polygon = HistoricDistrict.getDistrict params[:lat], params[:long]
@cosa_district_polygon = CosaCouncilDistrict.getDistrict params[:lat], params[:long]
@cons_district_polygon = ConservationDistrict.getDistrict params[:lat], params[:long]
end

@response = { :lat => @lat,
Expand All @@ -37,7 +41,9 @@ def index
:in_hist_district => @in_hist_district,
:hist_district_polygon => @hist_district_polygon,
:in_cosa_district => @in_cosa_district,
:cosa_district_polygon => @cosa_district_polygon
:cosa_district_polygon => @cosa_district_polygon,
:in_cons_district => @in_cons_district,
:cons_district_polygon => @cons_district_polygon
}
respond_with(@response)
end
Expand Down
32 changes: 32 additions & 0 deletions app/models/conservation_district.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class ConservationDistrict < ActiveRecord::Base
# self.primary_key = 'gid'
# self.table_name = 'historicdistricts'

COORD_SYS_REF = 4326; # The coordinate system that will be used as the reference and is now Latitude and Longitude Coord System
COORD_SYS_AREA = 2278; # The coordinate system used in the data Texas South Central Coordinate System
COORD_SYS_ZONE = 0; # The coordinate system used in the actual data but somehow it was wiped to 0, so put it back into the same one to check

def self.inDistrict? lat, long
# figure out if it is in a specific area in
@spec_area = ConservationDistrict.where("ST_Contains(geom, ST_SetSRID(ST_Transform(ST_SetSRID(ST_MakePoint(?, ?), ?), ?), ?))",
long,
lat,
COORD_SYS_REF,
COORD_SYS_AREA,
COORD_SYS_ZONE)

return @spec_area.exists?
end

def self.getDistrict lat, long
# figure out if it is in a specific area in historical district
@area_in_geojson = ConservationDistrict.find_by_sql("select name, ordinance, ordinance_date, shape_leng, shape_area, ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, #{COORD_SYS_AREA}), #{COORD_SYS_REF}))
from conservation_districts
where ST_Contains(geom,
ST_SetSRID(ST_Transform(ST_SetSRID(ST_MakePoint(#{long}, #{lat}),#{COORD_SYS_REF}), #{COORD_SYS_AREA}), #{COORD_SYS_ZONE}))")


return @area_in_geojson.first
end

end
13 changes: 13 additions & 0 deletions db/migrate/20140502223732_create_conservation_districts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateConservationDistricts < ActiveRecord::Migration
def change
create_table :conservation_districts do |t|
t.string :name
t.string :ordinance
t.string :ordinance_date
t.float :shape_leng
t.float :shape_area
t.geometry :geom
t.timestamps
end
end
end
13 changes: 12 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140414080232) do
ActiveRecord::Schema.define(version: 20140502223732) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "postgis"

create_table "conservation_districts", force: true do |t|
t.string "name"
t.string "ordinance"
t.string "ordinance_date"
t.float "shape_leng"
t.float "shape_area"
t.datetime "created_at"
t.datetime "updated_at"
t.spatial "geom", limit: {:srid=>0, :type=>"geometry"}
end

create_table "cosa_council_districts", force: true do |t|
t.integer "district"
t.string "name"
Expand Down
Binary file not shown.
Loading