I need to insert a point into table of type postgres, I tried:
\DB::statement("SET search_path = postgis, public;");
\DB::statement("INSERT INTO points (latlong) VALUES( ST_GeomFromText('POINT(-71.060316 48.432044)', 4326));");
but I got error:
SQLSTATE[42883]: Undefined function: 7 ERROR: function st_geomfromtext(unknown, integer) does not exist
LINE 1: INSERT INTO points (latlong) VALUES(ST_GeomFromText('POINT(-...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. (SQL: INSERT INTO points (latlong) VALUES(ST_GeomFromText('POINT(-71.060316 48.432044)', 4326));)
I am using postgres 9.4.5 with postgis installed .. any idea?
Install PostGIS using something like CREATE EXTENSION IF NOT EXISTS postgis
Creating a geometry by formatting a WKT string for ST_GeomFromText is not the best way to make a geometry (slower, lossy, error prone, etc.), unless your source data is already text. To make a point geometry from two floating point values, use something like:
DB::insert('INSERT INTO points (latlong) VALUES(ST_SetSRID(ST_MakePoint(?, ?), 4326))',
[lng, lat]);
Related
I am trying to run this function
SELECT public.CreateTopology('topo1',4326,0);
which gives me
ERROR: function public.createtopology(unknown, integer, integer) does not exist
LINE 1: select public.CreateTopology('topo1',4326,0);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 8
I can use other PostGIS function without trouble. This one however does not work. Note, there are many schems in my database. Why is that?
The third parameter is optional, but if present is data type double precision, if omitted defaults to 0. (see Postgis documentation CreateTopology. So try
SELECT public.CreateTopology('topo1',4326,0::double precision);
OR
SELECT public.CreateTopology('topo1',4326,0.0);
OR
SELECT public.CreateTopology('topo1',4326);
UPDATE: As posted 'topo1' is a string literal. But it needs to be Topology. You need to correct the data type.
I am currently new to PostgreSQL and I am implementing pgrouting using Esri Shapefiles.
The query I am writing is :
SELECT pgr_createTopology('point_file'::text,0.000001,'the_geom'::text, 'gid'::text);
"point_file" is the table name ,"the_geom" is the geometry column, and "gid" is the id column.
The error I am getting is :
ERROR: function pgr_createtopology(text, numeric,text, text) does not exist
LINE 1: SELECT pgr_createTopology('point_file'::text,0.000001,'th...
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 8
NOTE: I have already added postgis as an extension.
I am using PostgreSQL 13 AND PostGIS 3.1.
i am using postgresql version :
"PostgreSQL 9.3.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2), 64-bit"
i have created 2 tables A and B with point and polygon as a data type.
now i want to know whether point is inside the polygon or not.
for this i am trying to use ST_Intersect(A.point_LatLong , B.polygon_abc);
my query is :
SELECT A.id
FROM A, B
WHERE A.name = 'callifornia'
AND ST_Intersect(A.point_LatLong , B.polygon_abc);
here point_latLong and polygon_abc are column name having datatype point and polygon in table A and B.
but this query gives an error :
ERROR: function st_intersect(point, polygon) does not exist
LINE 3: WHERE city.city_name = 'callifornia' AND ST_intersect(city.c...
HINT: No function matches the given name and argument types. You might need to add
explicit type casts.
How can I solve this problem? I even not be able to use any other spatial method in postgresql like st_contains() etc let me know if you have any solution.
You are trying to mix PostgreSQL's built-in (limited, but useful) geometric types with PostGIS functions. It sounds like you didn't install PostGIS, either. You've also typo'd the function name, it's ST_Intersects not ST_Intersect.
First, if you want to use PostGIS, make sure it's installed and then:
CREATE EXTENSION postgis;
Next, you'll probably find that you can't actually call ST_Intersects with a point and a polygon. PostGIS works with its own geometry type. It has some converters for the PostgreSQL internal types, but they're only limited. So calling PostGIS functions with primitive geometric types can result in errors like:
postgres=# SELECT ST_Intersects( polygon( box(point(0,0), point(10,10)) ), point(5,5) );
ERROR: function st_intersects(polygon, point) does not exist
LINE 1: SELECT ST_Intersects( polygon( box(point(0,0), point(10,10))...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
You'll often have to convert them to PostGIS's own geometry type. PostGIS provides some explicit casts for this for most types, e.g.:
postgres=# SELECT ST_Intersects(
polygon( box(point(0,0), point(10,10)) )::geometry,
point(5,5)::geometry
);
st_intersects
---------------
t
(1 row)
So in your query, that'd be:
ST_Intersects(A.point_LatLong::geometry , B.polygon_abc::geometry);
I have a function in postgres that inserts data to a table, and one of the columns is of type point.
I don't know how to save my gotten data to an acceptable form for the function to save my data.
The problematic code in question is :
CREATE OR REPLACE FUNCTION db."setMessage"(eml text, msg text, lat text, lng text)
...
INSERT INTO
db.messages
VALUES
(DEFAULT,
id,
$2,
DEFAULT,
ST_SetSRID(ST_MakePoint($3::float, $4::float), 4326)
);
The error received when i call the function is:
ERROR: function st_makepoint(double precision, double precision) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Context: PL/pgSQL function "setMessage" line 9 at SQL statement
I have tries to save the point in string format ('POINT(12.22343 64.22233)'), tried not casting the st_makepoint arguments, and inserting without the outer function (ST_SetSRID).
could anyone tell me what I'm doing wrong?
SOLUTION:
So the method of success was following this link to get the needed libraries. after that i created the required extensions, and now i have access to the desired functions.
To install PostGIS, follow the instructions for your operating system at https://postgis.net/install.
Then, to enable it on your db you can do CREATE EXTENSION postgis; from psql or PGAdmin.
I had a similar problem, that postgres didn't find the function st_makepoint even though postgis extension was installed and I used the correct types for arguments. It turned out that the search path did not contain postgis.
Solution was: alter database my_db set search_path = my_schema, public, postgis;
Hope it helps somebody.
I tried to re-install postgis extension and have tried many soluations but did not work for me.
I just edit my query and put extensions keyword before functions name like this:
INSERT INTO
db.messages
VALUES
(DEFAULT,
id,
$2,
DEFAULT,
extensions.ST_SetSRID(extensions.ST_MakePoint($3::float, $4::float), 4326)
);
That worked for me.
I am attempting to use COPY FROM STDIN to import data into my table. One of the columns in my table is of type geometry. My command looks something like this...
COPY "WeatherStations" ("Station_ID", "Station_Code", "Station_Name", "Station_Location") FROM stdin;
1 KAVP WILKES-BARRE ST_GeomFromText('POINT(41.338055 -75.724166)')
2 KOKV WINCHESTER ST_GeomFromText('POINT(39.143333 -78.144444)')
3 KSHD SHENANDOAH ST_GeomFromText('POINT(38.263611 -78.896388)')
...
However, I think it is attempting to insert the text "ST_GeomFromText('POINT..." and failing instead of evaluating the expression and inserting the result of the expression. Does anyone know what might be going on here and how I can get the actual geoms inserted?
I had a bad time figuring out how to bulk copy/load geometry data into PostGIS using the COPY FROM STDIN command, I couldn't find official documentation on this topic.
Altering the column during the bulk load (the ALTER TABLE / SET DATA TYPE / USING) was not an option to me because it is only supported in PostGIS 2.0+ for the Geometry type, nor was acceptable the use of a temporary table.
There is indeed a direct way to do it (at least in PostGIS 1.5.2+).
You can simply rewrite the data for your copy statement this way, using a simple WKT (Well-known text) representation for your Geometry data:
1 KAVP WILKES-BARRE POINT(41.338055 -75.724166)
2 KOKV WINCHESTER POINT(39.143333 -78.144444)
3 KSHD SHENANDOAH POINT(38.263611 -78.896388)
If you have enforced a SRID constraint on the geometry column you'll have to use the following syntax (in this example the SRID is 4326) known as EWKT (Extended Well-Known Text, which is a PostGIS specific format):
1 KAVP WILKES-BARRE SRID=4326;POINT(41.338055 -75.724166)
2 KOKV WINCHESTER SRID=4326;POINT(39.143333 -78.144444)
3 KSHD SHENANDOAH SRID=4326;POINT(38.263611 -78.896388)
Closing note: there must be no space between "POINT" and the opening parenthesis "(", or the COPY will still return error saying your geometry data has an invalid format.
You could omit the function wrapping the text, import into a temporary table with text column, and then run INSERT/SELECT into the permanent table with the function doing the conversion in that step.
INSERT INTO "WeatherStations"
("Station_ID", "Station_Code", "Station_Name", "Station_Location")
SELECT "Station_ID", "Station_Code", "Station_Name",
ST_GeomFromText("Station_Location")
FROM "TempWeatherStations";
You will keep all the values in .csv file and try like this:
CAT /path/file/demo.csv | psql -u <username> -h <localhost> -d<database>
-c "COPY "WeatherStations" ("Station_ID", "Station_Code", "Station_Name",
"Station_Location") FROM stdin;"
This will work.
Point's value looks something like this: 0101000020E6100000DA722EC555552B40CDCCCCCCCC0C4840.
I typically keep latitude and longitude columns in my tables and build spatial data with triggers.
I don't know how to copy POINTs from stdin otherwise.