Created
April 17, 2015 11:24
-
-
Save phildionne/380b9ba5272bf2017355 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
# Points according to Geojson specifications (X, Y) or (Longitude, Latitude) | |
sequence :point do | |
[ | |
[38.15704300068319, 82.64793458394706], | |
[65.25863617658615, -24.040317703038454], | |
[-144.94273960590363, 20.84642690140754], | |
[137.46707799844444, 80.3652603412047], | |
[-131.11246040090919, 3.13029068056494], | |
[-37.99821515567601, 70.2160071535036], | |
[-117.68862806260586, 69.35145386494696], | |
[81.27806204371154, 64.69108066521585], | |
[-177.8253368474543, 73.30492191016674], | |
[25.811246875673532, 43.99280528537929], | |
[68.29892839305103, 39.888890753500164], | |
[71.6192516963929, 69.36868672259152], | |
[7.61227791197598, -39.74393466487527], | |
[158.4781111869961, -58.95891933236271], | |
[-56.084979604929686, -69.5823574019596], | |
[-168.59097065404058, -59.04838265385479], | |
[-75.40441389195621, 5.477109532803297], | |
[58.01891759969294, 75.7381532387808], | |
[1.6819019615650177, -11.015902454964817], | |
[53.53394695557654, -67.35375837888569], | |
[3.4653446450829506, -25.61930435243994], | |
[129.04672460630536, -67.9163345368579], | |
[-119.32041856460273, 83.64995854441077], | |
[172.17046014033258, 81.00605474319309], | |
[-84.84171300195158, -72.85246434621513], | |
[43.81623689085245, -26.792520680464804], | |
[-30.67510787397623, 13.308199332095683], | |
[-161.64825341664255, -81.85833847615868], | |
[-15.205352967604995, -51.060410952195525], | |
[-19.80181029997766, -42.03691776841879], | |
[-108.92249040305614, 53.78595612477511], | |
[-44.93774735368788, -0.711731999181211], | |
[26.306544933468103, -19.489880078472197], | |
[57.47007066383958, -23.21849036961794], | |
[-53.60694997943938, -45.83582213614136], | |
[67.04049962572753, 14.89575320854783], | |
[-128.63802401348948, -0.9684758959338069], | |
[152.3939185962081, -17.419028556905687], | |
[-110.35916863940656, 46.09001479111612], | |
[-0.3085863031446934, 4.749766155146062], | |
[112.61560739949346, -36.49627424776554], | |
[-6.241376241669059, -40.5140094878152], | |
[142.97778236679733, 52.921161856502295], | |
[-114.74306534975767, -32.21518941689283], | |
[158.24760063551366, 23.234792961739004], | |
[-12.79419969767332, -62.48285582754761], | |
[-93.76410928554833, 56.25241817906499], | |
[-21.279821041971445, -13.630776540376246], | |
[79.47377423755825, -50.505535919219255], | |
[-147.32001146301627, 40.547768818214536] | |
].sample | |
end | |
sequence :geojson_point do | |
{ | |
type: "Point", | |
coordinates: FactoryGirl.generate(:point) | |
} | |
end | |
sequence :geojson_line_string do | |
{ | |
type: "LineString", | |
coordinates: [FactoryGirl.generate(:point), FactoryGirl.generate(:point)] | |
} | |
end | |
sequence :geojson_polygon do | |
point = FactoryGirl.generate(:point) | |
{ | |
type: "Polygon", | |
coordinates: [ | |
[ | |
point, | |
FactoryGirl.generate(:point), | |
FactoryGirl.generate(:point), | |
FactoryGirl.generate(:point), | |
FactoryGirl.generate(:point), | |
point | |
] | |
] | |
} | |
end | |
factory :geojson_feature, class: Hash do | |
initialize_with { attributes } | |
type "Feature" | |
properties Hash.new | |
trait :point do | |
geometry { generate(:geojson_point) } | |
end | |
trait :line_string do | |
geometry { generate(:geojson_line_string) } | |
end | |
trait :polygon do | |
geometry { generate(:geojson_polygon) } | |
end | |
end | |
factory :geojson_feature_collection, class: Hash do | |
initialize_with { attributes } | |
transient do | |
feature_count { rand(1..10) } | |
bbox [FactoryGirl.generate(:point), FactoryGirl.generate(:point)].flatten | |
end | |
type "FeatureCollection" | |
trait :point do | |
features { build_list(:geojson_feature, feature_count, :point) } | |
end | |
trait :line_string do | |
features { build_list(:geojson_feature, feature_count, :line_string) } | |
end | |
trait :polygon do | |
features { build_list(:geojson_feature, feature_count, :polygon) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment