problem with reading shapefile

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with reading shapefile

Meshal Al-Harbi
Hi folks,

I have a CSV file that contains a company name, lat, and long. I converted this CSV file into a shapefile. When I add this shapefile into the model from the display wizard, it puts all the companies at their right locations. However, when I try to read the CSV file using this code it gives extra companies right in the middle of the street which is not possible. Basically it doesn't give the same result although they have the same data. 

The code for reading from CSV:

try {
Scanner scanner = new Scanner(new File("Businesses with names and within the area.csv"));
 while(scanner.hasNextLine()){  
   
       String x = scanner.nextLine();                  // Extract that line
       String[] values = x.split(",");         // Split that line at the commas
       SME agent=new SME();
       context.add(agent);
       Coordinate coord = new Coordinate((Double.parseDouble(values[2])),(Double.parseDouble(values[1])));
       Point geom = fac.createPoint(coord);
geography.move(agent, geom);
   }
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

By the way when I read the same shapefile using the following code, it also gives extra companies in the middle of the street. It only work correctly when I add the shapefile from the display wizard.

File shapefile=null;
ShapefileLoader<SME> SMELoader=null;
try{
shapefile=new File("CSV_point.shp");
SMELoader=new ShapefileLoader<SME>(SME.class, shapefile.toURL(), geography, context);
}
catch(java.net.MalformedURLException e){
e.printStackTrace();
}
while(SMELoader.hasNext()){
SMELoader.next();


Could you please tell me what;s wrong?

Thanks in advance,

------------------------------------------------------------------------------

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: problem with reading shapefile

srcnick
Is it possible that some company names or data in the csv file contains a “,” in which case the parse below won’t work correctly? We recommend using opencsv which comes with Simphony to parse csv files. 


Nick

On Sep 8, 2016, at 11:50 AM, Meshal Al-Harbi <[hidden email]> wrote:

Hi folks,

I have a CSV file that contains a company name, lat, and long. I converted this CSV file into a shapefile. When I add this shapefile into the model from the display wizard, it puts all the companies at their right locations. However, when I try to read the CSV file using this code it gives extra companies right in the middle of the street which is not possible. Basically it doesn't give the same result although they have the same data. 

The code for reading from CSV:

try {
Scanner scanner = new Scanner(new File("Businesses with names and within the area.csv"));
 while(scanner.hasNextLine()){  
   
       String x = scanner.nextLine();                  // Extract that line
       String[] values = x.split(",");         // Split that line at the commas
       SME agent=new SME();
       context.add(agent);
       Coordinate coord = new Coordinate((Double.parseDouble(values[2])),(Double.parseDouble(values[1])));
       Point geom = fac.createPoint(coord);
geography.move(agent, geom);
   }
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

By the way when I read the same shapefile using the following code, it also gives extra companies in the middle of the street. It only work correctly when I add the shapefile from the display wizard.

File shapefile=null;
ShapefileLoader<SME> SMELoader=null;
try{
shapefile=new File("CSV_point.shp");
SMELoader=new ShapefileLoader<SME>(SME.class, shapefile.toURL(), geography, context);
}
catch(java.net.MalformedURLException e){
e.printStackTrace();
}
while(SMELoader.hasNext()){
SMELoader.next();


Could you please tell me what;s wrong?

Thanks in advance,
------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: problem with reading shapefile

Meshal Al-Harbi
Thank you Nick for reply.

 If I use the same generated shapefile with the following code, it gives different results than if I add the same exact shapefile from the display wizard !!

This is the code again:

File shapefile=null;
 ShapefileLoader<SME> SMELoader=null;
 try{
 shapefile=new File("CSV_point.shp");
 SMELoader=new ShapefileLoader<SME>(SME.class, shapefile.toURL(), geography, context);
 }
 catch(java.net.MalformedURLException e){
 e.printStackTrace();
 }
 while(SMELoader.hasNext()){
 SMELoader.next();
}

see the attached picture, it may clarifies the issue.

Thanks,

On Fri, Sep 9, 2016 at 1:38 PM, Nick Collier <[hidden email]> wrote:
Is it possible that some company names or data in the csv file contains a “,” in which case the parse below won’t work correctly? We recommend using opencsv which comes with Simphony to parse csv files. 


Nick

On Sep 8, 2016, at 11:50 AM, Meshal Al-Harbi <[hidden email]> wrote:

Hi folks,

I have a CSV file that contains a company name, lat, and long. I converted this CSV file into a shapefile. When I add this shapefile into the model from the display wizard, it puts all the companies at their right locations. However, when I try to read the CSV file using this code it gives extra companies right in the middle of the street which is not possible. Basically it doesn't give the same result although they have the same data. 

The code for reading from CSV:

try {
Scanner scanner = new Scanner(new File("Businesses with names and within the area.csv"));
 while(scanner.hasNextLine()){  
   
       String x = scanner.nextLine();                  // Extract that line
       String[] values = x.split(",");         // Split that line at the commas
       SME agent=new SME();
       context.add(agent);
       Coordinate coord = new Coordinate((Double.parseDouble(values[2])),(Double.parseDouble(values[1])));
       Point geom = fac.createPoint(coord);
geography.move(agent, geom);
   }
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

By the way when I read the same shapefile using the following code, it also gives extra companies in the middle of the street. It only work correctly when I add the shapefile from the display wizard.

File shapefile=null;
ShapefileLoader<SME> SMELoader=null;
try{
shapefile=new File("CSV_point.shp");
SMELoader=new ShapefileLoader<SME>(SME.class, shapefile.toURL(), geography, context);
}
catch(java.net.MalformedURLException e){
e.printStackTrace();
}
while(SMELoader.hasNext()){
SMELoader.next();


Could you please tell me what;s wrong?

Thanks in advance,
------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
Eng.Meshal Al-beedhani

------------------------------------------------------------------------------

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest

agents' problem .jpg (74K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: problem with reading shapefile

srcnick
Does the shapefile have a projection associated with it? I suppose its possible that the display is respecting that, but when you load it its different from the one set in the geography.

Nick


On Sep 9, 2016, at 1:25 PM, Meshal Al-Harbi <[hidden email]> wrote:

Thank you Nick for reply.

 If I use the same generated shapefile with the following code, it gives different results than if I add the same exact shapefile from the display wizard !!

This is the code again:

File shapefile=null;
 ShapefileLoader<SME> SMELoader=null;
 try{
 shapefile=new File("CSV_point.shp");
 SMELoader=new ShapefileLoader<SME>(SME.class, shapefile.toURL(), geography, context);
 }
 catch(java.net.MalformedURLException e){
 e.printStackTrace();
 }
 while(SMELoader.hasNext()){
 SMELoader.next();
}

see the attached picture, it may clarifies the issue.

Thanks,

On Fri, Sep 9, 2016 at 1:38 PM, Nick Collier <[hidden email]> wrote:
Is it possible that some company names or data in the csv file contains a “,” in which case the parse below won’t work correctly? We recommend using opencsv which comes with Simphony to parse csv files. 


Nick

On Sep 8, 2016, at 11:50 AM, Meshal Al-Harbi <[hidden email]> wrote:

Hi folks,

I have a CSV file that contains a company name, lat, and long. I converted this CSV file into a shapefile. When I add this shapefile into the model from the display wizard, it puts all the companies at their right locations. However, when I try to read the CSV file using this code it gives extra companies right in the middle of the street which is not possible. Basically it doesn't give the same result although they have the same data. 

The code for reading from CSV:

try {
Scanner scanner = new Scanner(new File("Businesses with names and within the area.csv"));
 while(scanner.hasNextLine()){  
   
       String x = scanner.nextLine();                  // Extract that line
       String[] values = x.split(",");         // Split that line at the commas
       SME agent=new SME();
       context.add(agent);
       Coordinate coord = new Coordinate((Double.parseDouble(values[2])),(Double.parseDouble(values[1])));
       Point geom = fac.createPoint(coord);
geography.move(agent, geom);
   }
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

By the way when I read the same shapefile using the following code, it also gives extra companies in the middle of the street. It only work correctly when I add the shapefile from the display wizard.

File shapefile=null;
ShapefileLoader<SME> SMELoader=null;
try{
shapefile=new File("CSV_point.shp");
SMELoader=new ShapefileLoader<SME>(SME.class, shapefile.toURL(), geography, context);
}
catch(java.net.MalformedURLException e){
e.printStackTrace();
}
while(SMELoader.hasNext()){
SMELoader.next();


Could you please tell me what;s wrong?

Thanks in advance,
------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
Eng.Meshal Al-beedhani
<agents' problem .jpg>


------------------------------------------------------------------------------

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: problem with reading shapefile

Meshal Al-Harbi
Hi Nick,

As I'm a new to Repast I am not fully sure if I understood the questions. However, I only have one geography projection in the project, and all the agents are in this projection.

By the way, in the same display I have a topography and ITN layers. I just found out that when I removed the topography and the ITN layers from the display that the agents set on them. The program reads both shapefiles correctly, and put all the agents from the shapefiles at their right positions.  I don't what the wrong is.

On Sep 9, 2016, at 7:02 PM, Nick Collier <[hidden email]> wrote:

Does the shapefile have a projection associated with it? I suppose its possible that the display is respecting that, but when you load it its different from the one set in the geography.

Nick


On Sep 9, 2016, at 1:25 PM, Meshal Al-Harbi <[hidden email]> wrote:

Thank you Nick for reply.

 If I use the same generated shapefile with the following code, it gives different results than if I add the same exact shapefile from the display wizard !!

This is the code again:

File shapefile=null;
 ShapefileLoader<SME> SMELoader=null;
 try{
 shapefile=new File("CSV_point.shp");
 SMELoader=new ShapefileLoader<SME>(SME.class, shapefile.toURL(), geography, context);
 }
 catch(java.net.MalformedURLException e){
 e.printStackTrace();
 }
 while(SMELoader.hasNext()){
 SMELoader.next();
}

see the attached picture, it may clarifies the issue.

Thanks,

On Fri, Sep 9, 2016 at 1:38 PM, Nick Collier <[hidden email]> wrote:
Is it possible that some company names or data in the csv file contains a “,” in which case the parse below won’t work correctly? We recommend using opencsv which comes with Simphony to parse csv files. 


Nick

On Sep 8, 2016, at 11:50 AM, Meshal Al-Harbi <[hidden email]> wrote:

Hi folks,

I have a CSV file that contains a company name, lat, and long. I converted this CSV file into a shapefile. When I add this shapefile into the model from the display wizard, it puts all the companies at their right locations. However, when I try to read the CSV file using this code it gives extra companies right in the middle of the street which is not possible. Basically it doesn't give the same result although they have the same data. 

The code for reading from CSV:

try {
Scanner scanner = new Scanner(new File("Businesses with names and within the area.csv"));
 while(scanner.hasNextLine()){  
   
       String x = scanner.nextLine();                  // Extract that line
       String[] values = x.split(",");         // Split that line at the commas
       SME agent=new SME();
       context.add(agent);
       Coordinate coord = new Coordinate((Double.parseDouble(values[2])),(Double.parseDouble(values[1])));
       Point geom = fac.createPoint(coord);
geography.move(agent, geom);
   }
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

By the way when I read the same shapefile using the following code, it also gives extra companies in the middle of the street. It only work correctly when I add the shapefile from the display wizard.

File shapefile=null;
ShapefileLoader<SME> SMELoader=null;
try{
shapefile=new File("CSV_point.shp");
SMELoader=new ShapefileLoader<SME>(SME.class, shapefile.toURL(), geography, context);
}
catch(java.net.MalformedURLException e){
e.printStackTrace();
}
while(SMELoader.hasNext()){
SMELoader.next();


Could you please tell me what;s wrong?

Thanks in advance,
------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
Eng.Meshal Al-beedhani
<agents' problem .jpg>


------------------------------------------------------------------------------

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: problem with reading shapefile

srcnick
Sorry, I mean GIS projection here, not simphony projection. The shapefile might have its own projection with a coordinate reference system (CRS) that doesn’t match the default CRS in the geography. The projection for the shapefile would be in a .prj file, I think.

Nick


On Sep 9, 2016, at 3:27 PM, Meshal Alharbi <[hidden email]> wrote:

Hi Nick,

As I'm a new to Repast I am not fully sure if I understood the questions. However, I only have one geography projection in the project, and all the agents are in this projection.

By the way, in the same display I have a topography and ITN layers. I just found out that when I removed the topography and the ITN layers from the display that the agents set on them. The program reads both shapefiles correctly, and put all the agents from the shapefiles at their right positions.  I don't what the wrong is.

On Sep 9, 2016, at 7:02 PM, Nick Collier <[hidden email]> wrote:

Does the shapefile have a projection associated with it? I suppose its possible that the display is respecting that, but when you load it its different from the one set in the geography.

Nick


On Sep 9, 2016, at 1:25 PM, Meshal Al-Harbi <[hidden email]> wrote:

Thank you Nick for reply.

 If I use the same generated shapefile with the following code, it gives different results than if I add the same exact shapefile from the display wizard !!

This is the code again:

File shapefile=null;
 ShapefileLoader<SME> SMELoader=null;
 try{
 shapefile=new File("CSV_point.shp");
 SMELoader=new ShapefileLoader<SME>(SME.class, shapefile.toURL(), geography, context);
 }
 catch(java.net.MalformedURLException e){
 e.printStackTrace();
 }
 while(SMELoader.hasNext()){
 SMELoader.next();
}

see the attached picture, it may clarifies the issue.

Thanks,

On Fri, Sep 9, 2016 at 1:38 PM, Nick Collier <[hidden email]> wrote:
Is it possible that some company names or data in the csv file contains a “,” in which case the parse below won’t work correctly? We recommend using opencsv which comes with Simphony to parse csv files. 


Nick

On Sep 8, 2016, at 11:50 AM, Meshal Al-Harbi <[hidden email]> wrote:

Hi folks,

I have a CSV file that contains a company name, lat, and long. I converted this CSV file into a shapefile. When I add this shapefile into the model from the display wizard, it puts all the companies at their right locations. However, when I try to read the CSV file using this code it gives extra companies right in the middle of the street which is not possible. Basically it doesn't give the same result although they have the same data. 

The code for reading from CSV:

try {
Scanner scanner = new Scanner(new File("Businesses with names and within the area.csv"));
 while(scanner.hasNextLine()){  
   
       String x = scanner.nextLine();                  // Extract that line
       String[] values = x.split(",");         // Split that line at the commas
       SME agent=new SME();
       context.add(agent);
       Coordinate coord = new Coordinate((Double.parseDouble(values[2])),(Double.parseDouble(values[1])));
       Point geom = fac.createPoint(coord);
geography.move(agent, geom);
   }
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

By the way when I read the same shapefile using the following code, it also gives extra companies in the middle of the street. It only work correctly when I add the shapefile from the display wizard.

File shapefile=null;
ShapefileLoader<SME> SMELoader=null;
try{
shapefile=new File("CSV_point.shp");
SMELoader=new ShapefileLoader<SME>(SME.class, shapefile.toURL(), geography, context);
}
catch(java.net.MalformedURLException e){
e.printStackTrace();
}
while(SMELoader.hasNext()){
SMELoader.next();


Could you please tell me what;s wrong?

Thanks in advance,
------------------------------------------------------------------------------
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
Eng.Meshal Al-beedhani
<agents' problem .jpg>



------------------------------------------------------------------------------

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest