Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm using Postgis functions st_dump and st_split to split a polygon based on line. Now, after splitting; output geometry stores in a database table as well. Here is the query:

insert into aoo(geom)
SELECT ST_AsTEXT ((ST_Dump(ST_Split(circle, line))).geom) As wkt
FROM (SELECT 
    ST_GeomFromText('LINESTRING(73.33393335342407 33.82005181729661,73.33685159683228 33.80960466650892)',4326) As line,
    (select geom As circle from aoo where gid=71) ) As foo;

But, the issue is I want to store other data with these geometries as well. Like

insert into aoo(geom,name)

but I don't what is the way to do it.

share|improve this question
    
What is the name of the field that you want to enter? is it also name? –  Devdatta Tengshe Jun 19 at 5:59

3 Answers 3

First of all don't use ST_AsText when you want a geometry back -- it just will cast back to geometry so a waste of cycles.

I'm not sure where your name field is coming from you want to insert, so I will assume it comes from your circle record. Note the trick is in your foo subselect you need to first list out all fields you want back.

INSERT INTO aoo(geom, name)
SELECT (ST_Dump(ST_Split(circle, line))).geom, foo.name
  FROM ST_GeomFromText('LINESTRING(73.33393335342407 33.82005181729661,73.33685159683228 33.80960466650892)',4326) As line 
  INNER JOIN
  (SELECT geom As circle, name from aoo where gid=71) As foo 
     ON ST_Intersects(line, foo.circle);
share|improve this answer
    
@LR1234567.. Actually, I want to enter the name field manually. It's not coming from somewhere. Entering it manually mean like any hard coded value we put into record. –  muzaffar Jun 23 at 12:09
    
In that case, why don't you just do: change my first line to SELECT (ST_Dump(ST_Split(circle, line))).geom, 'What I want here' As name –  LR1234567 Jun 24 at 22:48

You should be able to do this:

Insert INTO aoo(geom, out_name)
SELECT ST_AsTEXT ((ST_Dump(ST_Split(circle, line))).geom) As wkt, in_name
FROM (SELECT 
    ST_GeomFromText('LINESTRING(73.33393335342407 33.82005181729661,73.33685159683228 33.80960466650892)',4326) As line,
    (select geom As circle from aoo where gid=71) ) As foo;

where out_name is the fieldname of the name field in the destination table & in_name is the fieldname of the name field in the source table

share|improve this answer
    
I just have one table as you can see in the query: linestring geometry is added manually while polygon geometry is taken from table aoo and I want to store the output also in the same table. –  muzaffar Jun 19 at 6:19
    
Shouldn't you use an update query in that case? –  Devdatta Tengshe Jun 19 at 6:21
    
I think I couldn't make my point clear. Splitted geometries are being successfully storing in the table. Actually, I want to store data for other columns along with geometry simultaneously. –  muzaffar Jun 19 at 6:37
up vote 0 down vote accepted

Well, others have tried well to answer my question. But those are not according to my requirements. What I did in this case is to handle the case at Server-end. Using PHP array, get the dumped geometries:

while ($row = pg_fetch_assoc($rs)) 
        {
            $result[] = $row['wkt'];
        }

By using above snippet each dumped geometry is stored at an index in $result array. Hence, we can use insert or update query to store data other than geometries. Cheers!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.