Skip to content

Instantly share code, notes, and snippets.

View glennpjones's full-sized avatar
🖥️
Focusing

Glenn glennpjones

🖥️
Focusing
View GitHub Profile
@glennpjones
glennpjones / province.txt
Last active January 29, 2020 18:17
Challenging multipolygon containing multiple polygons
AsText:
MULTIPOLYGON(((119037.63 380508.02,119058.88 380528.13,119066.03 380525.13,119071.89 380521.44,119079.62 380516.6,119098.49 380503.72,119112.23 380495.59,119121.9 380491.28,119139.65 380514.56,119144.5 380520.25,119172.01 380547.79,119233.73 380504.38,119234.6 380491.06,119152.93 380463.19,119163.73 380447.1,119171.58 380431.85,119176.48 380419.44,119181.49 380401.18,119183.33 380389.3,119166.54 380386.6,119146.12 380382.97,119104.35 380372.91,119045.3 380358.31,118999.85 380352.57,118964.59 380422.53,118977.99 380431.03,118984.87 380437.41,118994.53 380446.83,118999.94 380453.99,119004.37 380461.03,119007.1 380466.65,119010.98 380475.9,119015.705 380483.399,119025.06 380494.67,119037.63 380508.02)),((122702.01 383544.841,122687.707 383556.946,122687.69 383556.96,122678.2 383561.44,122681.035 383565.051,122689.733 383576.129,122697.655 383586.219,122706.338 383597.278,122715.04 383608.362,122723.609 383619.276,122739.306 383639.269,122754.888 383659.116,122761.669 383667.753,122780.36 383691.56,122792
irb(main):013:0> Land.in_area(s.area).to_sql
(0.5ms) SELECT * FROM lands WHERE ST_Contains(POLYGON ((4.949341 52.427548, 5.048218 52.347085, 4.924622 52.290003, 4.790039 52.288323, 4.779053 52.357151, 4.828491 52.420848, 4.949341 52.427548)), geom)
ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: syntax error at or near "52.427548")
LINE 1: ... WHERE ST_Contains(POLYGON ((4.949341 52.427548,...
^
: SELECT * FROM lands WHERE ST_Contains(POLYGON ((4.949341 52.427548, 5.048218 52.347085, 4.924622 52.290003, 4.790039 52.288323, 4.779053 52.357151, 4.828491 52.420848, 4.949341 52.427548)), geom)
@glennpjones
glennpjones / routes.rb
Last active October 29, 2015 13:55
Rails Routing
require 'domain_constraint'
Rails.application.routes.draw do
constraints DomainConstraint.new('domainname-one.com') do
root :to => 'landingpages#show', as: '/'
end
constraints DomainConstraint.new('domainname-two.io') do
root :to => 'landingpages#show', as: '/'
@glennpjones
glennpjones / domain_constraint.rb
Created October 29, 2015 13:36
Rails Routing
class DomainConstraint
def initialize(domain)
@domains = [domain].flatten
end
def matches?(request)
@domains.include? request.domain
end
end