I'd like to get random coordinates into the red bounded area:
The code below is what I've tried so far but I'm not sure if this does what it is supposed to do since this is a mix of a few codes and I've never seen a code which samples random coordinates into an original geometry of a such location.
library(raster)
library(sp)
library(rgeos)
library(rgdal)
library(dismo)
library(rgdal)
library(sf)
library(rgdal)
library(maptools)
library(scales)
d=getData('worldclim',lat=-5.49839,lon=-39.32062,res=0.5,var='bio')#these la and lon are the center coordinates
setwd('C:/Users/DAVI/Desktop/Nova pasta (2)')#My dir
estados=readShapePoly("lim_unidade_federacao_a.shp")## This is a SpatialPolygonsDataFrame keeping all states of Brazil, the download is after the question.
estados[estados@data$nome=="Ceará",]## I'm just interested about Ceara
plot(estados[estados@data$nome=="Ceará",])##Note that it keeps the geometry of the state which I'm interested in
ceara=spsample(estados[estados@data$nome=="Ceará",],n=1000,type="random")##Sampling random cordinates
This runs with no problem but as I've told I'm not sure if it's right.
Data used: https://drive.google.com/file/d/1l5dOt5l2f6DZz3dRq7p0Ig9Q1iE8BdLB/view?usp=sharing