I could really use some direction here. I'm fairly new to PostGIS, and I'm coming up with nothing in my search for answers.
I'm pulling in various shapefiles with several different projections (EPSG/SRID). I extract the GEOGCS from the .prj file, look up the SRID number using https://developers.arcgis.com/javascript/3/jshelp/gcs.html, matching it and import them with shp2pgsql -s. This is pretty straight forward. Generally it's working fine. Other times, not so much.
When it's not working, the coordinates I'm getting are like 153009.914, 5497499.47 (clearly off the map). I believe that this is a simple projection issue, and I'm not using the right SRID.
.prj:
PROJCS["EO_Lambert_Conformal_Conic",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",1000000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-84.0],PARAMETER["Standard_Parallel_1",44.5],PARAMETER["Standard_Parallel_2",54.5],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
Import:
# shp2pgsql -c -s 4269 -W UTF-8 -I /Shape/ont/DIVISION.shp ont | psql -U postgres -d shape
Structure:
Column | Type | Collation | Nullable | Default
------------+-----------------------------+-----------+----------+-------------------------------------------
gid | integer | | not null | nextval('ont_gid_seq'::regclass)
objectid | integer | | |
ed_id | numeric | | |
pd_number | numeric | | |
pd_label | character varying(64) | | |
ed_name_en | character varying(64) | | |
ed_name_fr | character varying(64) | | |
shape_leng | numeric | | |
shape_area | numeric | | |
geom | geometry(MultiPolygon,4269) | | |
Indexes:
"ont_pkey" PRIMARY KEY, btree (gid)
"ont_geom_idx" gist (geom)
SQL:
select ST_Astext(geom) AS coordinates FROM ont limit 1;
Result:
**MULTIPOLYGON(((574380.4001 4808575.0399,574434.7803 4808545.44,574496.2521 4808512.3351,............... ***etc.
What am I doing wrong?
Thank you for any insight!
Simplifying a bit, the SRID you are using is the one of the datum (The geogCS, geographic Coordinate System), i.e. the description of the "round" earth. Unit is degree and all coordinates are +- 180 / +- 90.
On top of that, there is projection which transform the coordinates to a flat surface. In your case, it is a special case of Lambert Conformal Conic, for Elections Ontario (EO_Lambert_Conformal_Conic), and the units are in meters.
Using this projection name, we can find that the SRID to use is 7149
Related
I have a DynamoDB table like depicted in the attached image and I'm looking for ways to query the table based on lon and lat fields. More specifically, I'm looking for all the results with Lon between X and Y and Lat between A and B.
Is there any way to do that ? I created indexes for both Lon and Lat but the values are strings.
Thanks a lot for your help !!
you can come up with a good hash function(lets say f) and have the below schema for dynamodb
| pk | sk | lat | lon | name
| hashvalue1 | 48.80#2.35#Fac | 48.80 | 2.35 | Fac du
| hashvalue1 | 48.83#2.36#Groupe| 48.83 | 2.36 | Groupe Hos
here f(48.80, 2.35) = hashvalue1
f(48.83, 2.36) = hashvalue1
And whenever you have to query for lat1 and lon1, calculate f(lat1, lon1) and query the db.
But the problem with this solution is coming up with a good hashing function because in the worst case you may have to recalculate hash of every entered value in db otherwise it may become a hot key. this approach is well documented here and here.
I would suggest go with elastic search, it will give you much more flexibility. in terms of future use cases.
I want to show a graph of minimum value, maximum value and difference between maximum and minimum for each timeslice.
It works ok for min and max
| parse "FromPosition *)" as FromPosition
| timeslice 2h
| max(FromPosition) ,min(FromPosition) group by _timeslice
but I couldn't find the correct way to specify the difference.
e.g.
| (max(FromPosition)- min(FromPosition)) as diffFromPosition by _timeslice
returns error -Unexpected token 'b' found.
I've tried a few different combinations to declare them on different lines as suggested on https://help.sumologic.com/05Search/Search-Query-Language/aaGroup. e.g.
| int(FromPosition) as intFromPosition
| max(intFromPosition) as maxFromPosition , min(intFromPosition) as minFromPosition
| (maxFromPosition - minFromPosition) as diffFromPosition
| diffFromPosition by _timeslice
without success.
Can anyone suggest the correct syntax?
Try this:
| parse "FromPosition *)" as FromPosition
| timeslice 2h
| max(FromPosition), min(FromPosition) by _timeslice
| _max - _min as diffFromPosition
| fields _timeslice, diffFromPosition
the group by is for the min and max functions to know what range to work with, not the group by for the overall search query. That's why you were getting the syntax errors and one reason I prefer to just use by as above.
For these kinds of queries I usually prefer a box plot where you would just do:
| min(FromPosition), pct(FromPosition, 25), pct(FromPosition, 50), pct(FromPosition, 75), max(FromPosition) by _timeslice
Then selecting box plot as the graph type. Looks great on a dashboard and provides a lot of detailed information about deviation and such at a glance.
I have a stream of numbers and in every cycle I need to count the average of last N of them. This can be, of course, solved using an array where I store the last N numbers and in every cycle I shift it, add the new one and count the average.
N = 3
+---+-----+
| a | avg |
+---+-----+
| 1 | |
| 2 | |
| 3 | 2.0 |
| 4 | 3.0 |
| 3 | 3.3 |
| 3 | 3.3 |
| 5 | 3.7 |
| 4 | 4.0 |
| 5 | 4.7 |
+---+-----+
First N numbers (where there "isn't enough data for counting the average") doesn't interest me much, so the results there may be anything/undefined.
My question is, can this be done without using an array, that is, with static amount of memory? If so, then how?
I'll do the coding myself - I just need to know the theory.
Thanks
Think of this as a black box containing some state. If you control the input stream, you can draw conclusions on the state. In your sliding window array-based approach, it is kind of obvious that if you feed a bunch of zeros into the algorithm after the original input, you get a bunch of averages with a decreasing number of non-zero values taken into account. The last one has just one original non-zero value, so if you multiply that my N you get the last input back. Using that and the second-to-last output which accounts for two non-zero inputs, you can reconstruct the second-to-last input, and so on.
So essentially your algorithm needs to maintain sufficient state to reconstruct the last N elements of input, at least if you formulate it as an on-line algorithm. I don't think an off-line algorithm can do any better, except if you consider it reading the input multiple times, but I don't have as strong an agument for that.
Of course, in some theoretical models you can avoid the array and e.g. encode all the state into a single arbitrary length integer, but that's just cheating the theory, and doesn't make any difference in practice.
I have a database. How to get all of colums types, and save it to a file. Distinctive types:
- Float
- Integer
- BigInteger
- String
My code is:
library(foreign)
library(memisc)
data <- read.spss("data.sav", use.value.labels = FALSE, max.value.labels = 100)
write.table(summary(data), "out.txt")
But, this code only distinguishes between two types of data... (numeric, String)
out sample:
Length Class Mode
SubsID 20582 -none- numeric
SubsID_RN 20582 -none- character
responseid 20582 -none- numeric
required output:
SubsID BigInteger
SubsID_RN String
responseid Integer
In R, the type system works differently from many of the other common languages. First of, everything in R is an object and one of the basic object types is the vector. The type of the vector itself is defined by the data that it contains. There are six atomic vector types which can be accessed by the typeof function. In the R documentation you can find the following table
+------------+----------+--------------+
| typeof | mode | storage.mode |
+------------+----------+--------------+
| logical | logical | logical |
| integer | numeric | integer |
| double | numeric | double |
| complex | complex | complex |
| character | character| character |
| raw | raw | raw |
+------------+----------+--------------+
As you can see, there is no difference between float and double or Integer and BigInteger. Also a String is just a character in R.
So in your case, if you want to know the specific basic type of each of your variables, you could use
lapply(data, typeof)
The R documentation has more information about objects and basic types:
http://cran.r-project.org/doc/manuals/r-release/R-lang.html#Objects
you can call the class or the type of your columns like this:
lapply(your_data_frame, class)
lapply(your_data_frame, typeof)
there's no such thing as 'BigInteger' in R. cf. data structures in hadley's adv-r for a more detailed explanation
http://i52.tinypic.com/5mmjoi.png <- take a peek here for the equations
Well, I've been studying matrices lately as I was interested more into the workings of changes of coordinate systems, obj->world and such. And I am looking at this couple of equations which are trying to interpret the vector-matrix multiplication as a linear combination of the matrix's row vectors scaled by the individual components of the u vector.
I do understand that they are just "reshaping" it into a few components, scaling the basis vectors of the translated coordinate system. The standard vector product is exactly the same as the combined row vectors scaled by x,y,z. It's more intuitive to see it when it is decomposed as such than just vague multiplications of the y coordinate with the second vector's x coordinate in the standard version and then added to the z and x values, how the dot product dictates.
My question is: How does one know what alterations are allowed, he just simply picks out the parts of the solution vector, sorting it by x, y and z. Do you simply do that or are there rules. The result certainly is correct, he has all the stuff necessary for a linear combination but how does he know what can and can't he touch?
A little more elaboration, even from the top, would be appreciated? Basically how and why does this work? Thanks everyone!
If I understand your question correctly, it's just a matter of grouping like terms. We start with regular multiplication uM:
| m11 m12 m13 |
| x y z | * | m21 m22 m23 | = | xm11+ym21+zm31 xm12+ym22+zm32 xm13+ym23+zm33 |
| m31 m32 m33 |
The author of your image wants to show that the dot product of the vector with each column is the same thing as taking a weighted sum of each row so that's how he breaks the resulting vector apart. He's free to break it apart any which way he wants so long as the final sum remains the same.
E.g.:
| xm11+ym21+zm31 xm12+ym22+zm32 xm13+ym23+zm33 | =
| xm11+ym21 xm12+ym22 xm13+ym23 | + | zm31 zm32 zm33 | =
| xm11 xm12 xm13 | + | ym21 ym22 ym23 | + | zm31 zm32 zm33 | =
| xm11 ym22 zm33 | + | ym21 zm32 xm13 | + | zm31 xm12 ym23 | =
| xm11+ym21+zm31-1 xm12+ym22+zm32-1 xm13+ym23+zm33-1 | + | 1 1 1 |
Etc.