Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgInsert hang with SPDF #12

Closed
imprompt opened this issue Oct 2, 2018 · 12 comments
Closed

pgInsert hang with SPDF #12

imprompt opened this issue Oct 2, 2018 · 12 comments

Comments

@imprompt
Copy link

imprompt commented Oct 2, 2018

I have RStudio running R v3.5.0 with rpostgis 1.4.1 running under CentOS 7.5 connecting to a postgres DB:

PostgreSQL 10.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit

Problem: pgInsert() hangs with no feedback when using spatial data.

What works:
test <- data.frame(x=0, y=0, a=1)
pgInsert(conn, name=c("public", "test_table1"), data.obj=test)

What doesn't work (hangs or crashes R):
coordinates(test) <- ~x + y
pgInsert(conn, name=c("public", "test_table2"), data.obj=test)

The database has the postgis extension
What would be the best way to diagnose the problem?

@imprompt
Copy link
Author

imprompt commented Oct 2, 2018

This works:
test <- data.frame(x=0, y=0, a=1)
pgInsert(conn, name=c("public", "test_table1"), data.obj=test)
pgMakePts(conn, name = c("public", "test_table1"), srid = 4326)

@dnbucklin
Copy link
Contributor

Hi Malcolm,

I'm not able to replicate the issue. Do you see any messages printed in the R console prior to the hang/crash?

@imprompt
Copy link
Author

imprompt commented Oct 2, 2018

Running using Rscript in a terminal gives the following:

Creating new table...
Using writeWKT from rgeos package...

 *** caught segfault ***
address 0x1, cause 'memory not mapped'

Traceback:
 1: rgeos::writeWKT(data.obj, byid = TRUE)
 2: pgInsertizeGeom(data.obj, geom, create.table, force.match, conn,     new.id, row.names, alter.names, partial.match, df.mode, geog)
 3: doTryCatch(return(expr), name, parentenv, handler)
 4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 5: tryCatchList(expr, classes, parentenv, handlers)
 6: tryCatch(expr, error = function(e) {    call <- conditionCall(e)    if (!is.null(call)) {        if (identical(call[[1L]], quote(doTryCatch)))             call <- sys.call(-4L)        dcall <- deparse(call)[1L]        prefix <- paste("Error in", dcall, ": ")        LONG <- 75L        sm <- strsplit(conditionMessage(e), "\n")[[1L]]        w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")        if (is.na(w))             w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L],                 type = "b")        if (w > LONG)             prefix <- paste0(prefix, "\n  ")    }    else prefix <- "Error : "    msg <- paste0(prefix, conditionMessage(e), "\n")    .Internal(seterrmessage(msg[1L]))    if (!silent && isTRUE(getOption("show.error.messages"))) {        cat(msg, file = outFile)        .Internal(printDeferredWarnings())    }    invisible(structure(msg, class = "try-error", condition = e))})
 7: try(pgi <- pgInsertizeGeom(data.obj, geom, create.table, force.match,     conn, new.id, row.names, alter.names, partial.match, df.mode,     geog))
 8: pgInsert(conn, name = c("public", "test_table2"), data.obj = test)
An irrecoverable exception occurred. R is aborting now ...
Segmentation fault (core dumped)

@imprompt
Copy link
Author

imprompt commented Oct 2, 2018

Same crash when writing spatial polygons when running:

e <- extent(c(0, 100, 0, 100))
e <- as(e, 'SpatialPolygons')
e <- SpatialPolygonsDataFrame(e, data=data.frame(a=1, b=2))
pgInsert(conn, name=c("public", "test_table3"), data.obj=e)

@imprompt
Copy link
Author

imprompt commented Oct 2, 2018

For points I can use the pgMakePts workaround, but for polygons I can't see a way to add a polygons column after writing a non-geometric data frame.

@dnbucklin
Copy link
Contributor

Could it be an issue with your rgeos package? Try:

library(rgeos)

test <- data.frame(x=0, y=0, a=1)
coordinates(test) <- ~x + y
writeWKT(test)
[1] "POINT (0.0000000000000000 0.0000000000000000)"

If so you may need to check/re-install your system GEOS package.

@imprompt
Copy link
Author

imprompt commented Oct 2, 2018

Thanks. It looks like regos is the problem, but reinstalling did not fix it.
So not a problem with rpostgis.
Thanks for your help.

@dnbucklin
Copy link
Contributor

If you install the package wkb, that would allow for limited use of pgInsert (e.g. for single-part points and polygons). But for all other geometry types, it needs the rgeos package and you'd still get the error. Good luck!

@imprompt
Copy link
Author

imprompt commented Oct 2, 2018

Working after building the latest system geos from source. Thanks for the package.

@basille
Copy link
Collaborator

basille commented Oct 2, 2018

Good to see that the problem is solved! @imprompt, for the record, could your give your previous and current versions of geos here (I understand the problem was not rgeos but the geos library directly)? Thanks!

@basille basille closed this as completed Oct 2, 2018
@imprompt
Copy link
Author

imprompt commented Oct 2, 2018

yum install geos: installed v3.4.1, which caused problem
installed v3.7.0 from source to fix.

@basille
Copy link
Collaborator

basille commented Oct 2, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants