Documentation ¶
Index ¶
- Constants
- func BboxToRect(bbox *shp.Box) (*rtree.Rect, error)
- func CommonHeadersMiddleware(h http.Handler) http.Handler
- func Index(w http.ResponseWriter, r *http.Request)
- func NewAPIHandler() http.Handler
- func NewViewportResponse(rect *rtree.Rect, zoom ZoomLevel, originalZoom int) *viewportResponse
- func ParseBboxToRect(s string) (*rtree.Rect, error)
- func ShpPolygonToGeojsonFeature(eps []*ElectoratePolygon) *geojson.Feature
- type Electorate
- type ElectorateID
- type ElectoratePolygon
- type EncodedGeometry
- type EncodedPolylineFeature
- type EncodedPolylineFeatureCollection
- type MarshalJSON
- type PollingPlace
- type ZoomLevel
Constants ¶
const DataFolder = "dist/national_elb"
DataFolder is the name of the folder we expect to find the shapefiles under zoomlevel bucket subfolders.
const EarthRadius = 6378.137
EarthRadius is a rough estimate of earth's radius in km at latitude 0 if earth was a perfect sphere.
const EarthRadiusSq = EarthRadius * EarthRadius
EarthRadiusSq is a rough estimate of earth's radius, squared.
const ( // DO NOT SUBMIT - replace with dummy key / empty key. MAPS_API_KEY string = "INSERT_API_KEY" )
const MaxZoomForAllElectorates = 8
MaxZoomForAllElectorates is an arbitrary zoom level after which the 'all electorates' dataset becomes too large to send in one response.
const MaxZoomLevelToIgnorePollingPlaces = 8
const MinNumOfElectoratesToReturnAll = 100
const MinZoomLevelToShowUngroupedPollingPlaces = 14
const PolygonAreaToViewportThresholdRatio = 32
const TypeElectorateIds = "electorate_ids"
const TypeElectorateLabel = "electorate_label"
const TypePollingPlace = "polling_place"
const TypePollingPlaceGroup = "polling_place_group"
Variables ¶
This section is empty.
Functions ¶
func CommonHeadersMiddleware ¶
CommonHeadersMiddleware adds common headers to the response and delegates to h for further processing of the request.
func Index ¶
func Index(w http.ResponseWriter, r *http.Request)
Index is the http.HandlerFunc that serve the index.html page of our application. It's exported because it is handled differently to the other API handlers.
func NewAPIHandler ¶
NewAPIHandler creates a single http.Handler for the election library HTTP API. Note that index is a separate http.HandlerFunc, as it requires a different set of headers.
func NewViewportResponse ¶
func ShpPolygonToGeojsonFeature ¶
func ShpPolygonToGeojsonFeature(eps []*ElectoratePolygon) *geojson.Feature
Types ¶
type Electorate ¶
type Electorate struct {
// contains filtered or unexported fields
}
Electorate is a derivative from the Australian Election Committee definition of an electorate, including its polygons as defined in the shapefile, an ID and a few other attributes.
func (*Electorate) AssignToFeature ¶
func (e *Electorate) AssignToFeature(feature *geojson.Feature)
func (Electorate) Bounds ¶
func (e Electorate) Bounds() *rtree.Rect
Bounds returns the bounding box of an electorate multi polygon.
type ElectorateID ¶
type ElectorateID string
ElectorateID is a unique identifier for an electorate in the system.
type ElectoratePolygon ¶
ElectoratePolygon contains a single polygon (out of possibly many) for an electorate, as well as GIS details such as centroid and GIS ID.
type EncodedGeometry ¶
type EncodedGeometry struct { Type string `json:"type"` Coordinates [][]string `json:"coordinates"` }
EncodedGeometry correlates to a GeoJSON linear ring geometry, replacing coordinates with the encoded representation.
type EncodedPolylineFeature ¶
type EncodedPolylineFeature struct { ID string `json:"id,omitempty"` Type string `json:"type"` BoundingBox []float64 `json:"bbox,omitempty"` // Geometry overrides the Feature's Geometry, allowing us to use the // encoded polyline algorithm. Geometry *EncodedGeometry `json:"geometry"` Properties map[string]interface{} `json:"properties"` }
EncodedPolylineFeature correlates to a GeoJSON feature, allowing EncodedGeometry to replace Geometry.
func (*EncodedPolylineFeature) MarshalJSON ¶
func (epf *EncodedPolylineFeature) MarshalJSON() ([]byte, error)
MarshalJSON returns JSON in a byte slice from a given encoded polyline feature.
type EncodedPolylineFeatureCollection ¶
type EncodedPolylineFeatureCollection struct { Type string `json:"type"` BoundingBox []float64 `json:"bbox,omitempty"` Features []MarshalJSON `json:"features"` }
EncodedPolylineFeatureCollection correlates to a GeoJSON feature collection, but allows flexibility in the features it contains.
func (*EncodedPolylineFeatureCollection) MarshalJSON ¶
func (epfc *EncodedPolylineFeatureCollection) MarshalJSON() ([]byte, error)
MarshalJSON returns JSON in a byte slice from a given encoded polyline feature collection.
type MarshalJSON ¶
MarshalJSON provides a common interface between geojson.Feature, geojson.FeatureCollection and our encoded polyline implementation.
type PollingPlace ¶
type PollingPlace struct { StateCode int StateAbbreviation string DivisionName string DivisionId int DivisionCode int PrettyPrintName string PollingPlaceId int Status string PremisesName string Address1 string Address2 string Address3 string AddressSuburb string AddressStateAbbreviation string Postcode int AdvPremisesName string AdvAddress string AdvLocality string AdviceBoothLocation string AdviceGateAccess string EntrancesDescription string Lat float64 Lng float64 CensusCollectionDistrict int WheelchairAccess string OrdinaryVoteEstimate int DeclarationVoteEstimate int NumberOrdinaryIssuingOfficers int NumberDeclarationIssuingOfficers int }